Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Base 64

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    25

    Base 64

    Salve amici,
    ho un problema nel riuscire a capire il funzionamento di un programma, scritto in java, che rappresenta la codifica e la decodifica in BASE 64.
    Qualcuno può darmi una mno per capire meglio il funzionamento della base 64, anche con un occhio a JAVA?
    Grazie per l'attenzione.
    :tongue: :tongue: :tongue:

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2002
    Messaggi
    315
    Base 64?!? Come sono codificate le cifre?
    Posta qui il codice che non capisci e vediamo che si puo' fare
    Ciao,
    Lorenzo

  3. #3
    Eccoti uno script in PHP che contiene le maggiori codifiche...

    http://freephp.html.it/script/view_script.asp?id=402

    Convertire il codice in Java non dovrebbe essere un problema!
    [Homepage] [Contattami]
    Powered by: Ubuntu - Debian - Gentoo
    Developing: Java - C++ - PHP

    [supersaibal]"Perchè tanto Debian è meglio"
    [/supersaibal]

  4. #4
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    25

    delucidazioni

    Scusami ma non conosco php e in Java sono ancora alle prime armi,se potresti essere più chiaro.
    GRAZIE!!!

  5. #5

    Re: delucidazioni

    Originariamente inviato da j@pn
    Scusami ma non conosco php e in Java sono ancora alle prime armi,se potresti essere più chiaro.
    GRAZIE!!!
    Tempo al tempo!
    [Homepage] [Contattami]
    Powered by: Ubuntu - Debian - Gentoo
    Developing: Java - C++ - PHP

    [supersaibal]"Perchè tanto Debian è meglio"
    [/supersaibal]

  6. #6
    Questo algoritmo fa un po' pena, però ti fa capire abbastanza come funge il tutto!!
    ps: produce un'errore negli ultimi bytes
    codice:
    import java.io.*;
    
    public class Base64Decoding {
    	StringBuffer buf;
    	StringBuffer buf2;
    	String Source;
    	FileInputStream FileI;
    	BufferedInputStream Bis;
    	FileOutputStream FileO;
    	DataOutputStream Bos;
    
    	public static void main(String[] args) {
    		Base64Decoding bas = new Base64Decoding("E:\\e.txt"); 
    	}
    
    	public Base64Decoding(String source) {
    		Source = source;
    		leggi();
    		traduci();
    		scrivi();
    	}
    	
    	public void scrivi(){
    		boolean ela=false;
    		int half=0;
    		int half2=0;
    		int tem=0;
    		String temp;
    		try {
    			FileO = new FileOutputStream(Source+".ex_");
    			Bos = new DataOutputStream(FileO);
    		for (int i = 0; i < buf2.length()-4; i=i+4) {
    			temp=buf2.substring(i,i+4);
    			if((temp.compareTo("0000"))==0){
    				tem=0x0;
    			}else if(temp.compareTo("0001")==0){
    				tem=0x1;
    			}else if(temp.compareTo("0010")==0){
    				tem=0x2;
    			}else if(temp.compareTo("0011")==0){
    				tem=0x3;
    			}else if(temp.compareTo("0100")==0){
    				tem=0x4;
    			}else if(temp.compareTo("0101")==0){
    				tem=0x5;
    			}else if(temp.compareTo("0110")==0){
    				tem=0x6;
    			}else if(temp.compareTo("0111")==0){
    				tem=0x7;
    			}else if(temp.compareTo("1000")==0){
    				tem=0x8;
    			}else if(temp.compareTo("1001")==0){
    				tem=0x9;
    			}else if(temp.compareTo("1010")==0){
    				tem=0xa;
    			}else if(temp.compareTo("1011")==0){
    				tem=0xb;
    			}else if(temp.compareTo("1100")==0){
    				tem=0xc;
    			}else if(temp.compareTo("1101")==0){
    				tem=0xd;
    			}else if(temp.compareTo("1110")==0){
    				tem=0xe;
    			}else if(temp.compareTo("1111")==0){
    				tem=0xf;
    			}
    			if(ela==false){
    				half=tem;
    				tem=0;
    				ela=true;
    			}else{
    				half2=tem;
    				tem=0;
    				ela=false;
    				int finale=(half*0x10)+half2;
    				Bos.writeByte(finale);
    				half=0;
    				half2=0;
    			}
    			
    		}
    		Bos.flush();
    		Bos.close();
    		
    		} catch(Exception e) {
    			System.err.println(e.toString());
    			e.printStackTrace();
    		}
    	}
    
    	public void leggi() {
    		try {
    			FileI = new FileInputStream(Source);
    			Bis = new BufferedInputStream(FileI);
    			buf = new StringBuffer();
    			int i = 0;
    			do {
    				i = Bis.read();
    				if ((i != -1) && ((char) i != '\r') && ((char) i != '\n')) {
    					buf.append((char) i);
    				}
    			} while (i != -1);
    		} catch (Exception e) {
    			System.err.println(e.toString());
    			e.printStackTrace();
    		}
    //		System.out.println("" + buf);
    	}
    
    	public void traduci() {
    		int a = 0;
    		buf2 = new StringBuffer();
    		for (int i = 0; i < buf.length(); i++) {
    			switch (buf.charAt(i)) {
    				case 'A' :
    					buf2.append("000000");
    					break;
    				case 'B' :
    					buf2.append("000001");
    					break;
    				case 'C' :
    					buf2.append("000010");
    					break;
    				case 'D' :
    					buf2.append("000011");
    					break;
    				case 'E' :
    					buf2.append("000100");
    					break;
    				case 'F' :
    					buf2.append("000101");
    					break;
    				case 'G' :
    					buf2.append("000110");
    					break;
    				case 'H' :
    					buf2.append("000111");
    					break;
    				case 'I' :
    					buf2.append("001000");
    					break;
    				case 'J' :
    					buf2.append("001001");
    					break;
    				case 'K' :
    					buf2.append("001010");
    					break;
    				case 'L' :
    					buf2.append("001011");
    					break;
    				case 'M' :
    					buf2.append("001100");
    					break;
    				case 'N' :
    					buf2.append("001101");
    					break;
    				case 'O' :
    					buf2.append("001110");
    					break;
    				case 'P' :
    					buf2.append("001111");
    					break;
    				case 'Q' :
    					buf2.append("010000");
    					break;
    				case 'R' :
    					buf2.append("010001");
    					break;
    				case 'S' :
    					buf2.append("010010");
    					break;
    				case 'T' :
    					buf2.append("010011");
    					break;
    				case 'U' :
    					buf2.append("010100");
    					break;
    				case 'V' :
    					buf2.append("010101");
    					break;
    				case 'W' :
    					buf2.append("010110");
    					break;
    				case 'X' :
    					buf2.append("010111");
    					break;					
    				case 'Y' :
    					buf2.append("011000");
    					break;
    				case 'Z' :
    					buf2.append("011001");
    					break;
    				case 'a' :
    					buf2.append("011010");
    					break;
    				case 'b' :
    					buf2.append("011011");
    					break;
    				case 'c' :
    					buf2.append("011100");
    					break;
    				case 'd' :
    					buf2.append("011101");
    					break;
    				case 'e' :
    					buf2.append("011110");
    					break;
    				case 'f' :
    					buf2.append("011111");
    					break;
    				case 'g' :
    					buf2.append("100000");
    					break;
    				case 'h' :
    					buf2.append("100001");
    					break;
    				case 'i' :
    					buf2.append("100010");
    					break;
    				case 'j' :
    					buf2.append("100011");
    					break;
    				case 'k' :
    					buf2.append("100100");
    					break;
    				case 'l' :
    					buf2.append("100101");
    					break;
    				case 'm' :
    					buf2.append("100110");
    					break;
    				case 'n' :
    					buf2.append("100111");
    					break;
    				case 'o' :
    					buf2.append("101000");
    					break;
    				case 'p' :
    					buf2.append("101001");
    					break;
    				case 'q' :
    					buf2.append("101010");
    					break;
    				case 'r' :
    					buf2.append("101011");
    					break;
    				case 's' :
    					buf2.append("101100");
    					break;
    				case 't' :
    					buf2.append("101101");
    					break;
    				case 'u' :
    					buf2.append("101110");
    					break;
    				case 'v' :
    					buf2.append("101111");
    					break;
    				case 'w' :
    					buf2.append("110000");
    					break;
    				case 'x' :
    					buf2.append("110001");
    					break;
    				case 'y' :
    					buf2.append("110010");
    					break;
    				case 'z' :
    					buf2.append("110011");
    					break;
    				case '0' :
    					buf2.append("110100");
    					break;
    				case '1' :
    					buf2.append("110101");
    					break;
    				case '2' :
    					buf2.append("110110");
    					break;
    				case '3' :
    					buf2.append("110111");
    					break;
    				case '4' :
    					buf2.append("111000");
    					break;
    				case '5' :
    					buf2.append("111001");
    					break;
    				case '6' :
    					buf2.append("111010");
    					break;
    				case '7' :
    					buf2.append("111011");
    					break;
    				case '8' :
    					buf2.append("111100");
    					break;
    				case '9' :
    					buf2.append("111101");
    					break;
    				case '+' :
    					buf2.append("111110");
    					break;
    				case '/' :
    					buf2.append("111111");
    					break;
    				case '=' :
    					a++;
    					break;
    			}
    			if(a==1){
    				buf2.delete((buf2.length()-2),buf2.length());
    			}else if (a==2){
    				buf2.delete((buf2.length()-4),buf2.length());
    			}
    		}
    	}
    }
    Blink@go

    "Non tutto quel che è oro brilla, Ne gli erranti sono perduti; Il vecchio ch'è forte non s'aggrinza, Le radici profonde non gelano.Dalle ceneri rinascerà un fuoco, L'ombra sprigionerà una scintilla, Nuova sarà la lama ormai rotta, E re quei ch'è senza corona."

    ------------
    Lang: java 1.4.1 Eclipse

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.