Charcrypt

Contenu du snippet

Ceci est un crypteur de fichier qui fonctionne bit à bit
Il à la particularité de créer lui même (aléatoirement) une clef que vous devez posséder pour pouvoir décrypter.

Source / Exemple :


import javax.swing.*;
import java.io.*;

public class BinaryFile
{
	private static byte opif()
	{
	byte pif =0;
	double test = Math.random();
	
	pif =(test<0.5 ? (byte)0 : (byte)1);
	
	return pif;
	}
	
	public static void main(String arg[]) throws IOException
	{
		
		String NomFichierI = JOptionPane.showInputDialog(null,"Adresse du fichier d'entrée:","test.txt");
		String NomFichierP = JOptionPane.showInputDialog(null,"Nom ou adresse de votre fichier clé :","clef.txt");
		String NomFichierO = JOptionPane.showInputDialog(null,"Nom du fichier à créer en sortie:","crea.txt");
		
		String choix[] = {"cryptage","décryptage"};
		String ModeExe = (String)JOptionPane.showInputDialog(null,"Que voulez vous effectuer?","PROCESS",JOptionPane.QUESTION_MESSAGE,null,choix,choix[0]);
		
		DataInputStream entree =  new DataInputStream(new FileInputStream(NomFichierI));
		DataOutputStream sortie = new DataOutputStream(new FileOutputStream(NomFichierO));
		
		
	  if(ModeExe == "cryptage")
	  {DataOutputStream pass = new DataOutputStream(new FileOutputStream(NomFichierP));
	
	  	byte bitI=0;
	  	byte bitP=0;
	  	byte n = 0;
	  	boolean eof = false;
	  	while(!eof)
	  	{
	  		try
	  		{
	  			bitI = entree.readByte();
	  			bitP = opif();
	  		}
	  		catch(EOFException e)
	  		{
	  			eof = true;
	  		}
	  		if(!eof){
	  			
	  			bitI = (byte)(~bitI);
				
				n= (byte)(bitI^bitP);
				
				sortie.writeByte(n);
				pass.writeByte(bitP);
				
				}
	  	}
	  	pass.close();
	  }else{
	  
	  if(ModeExe == "décryptage")
	  {DataInputStream pass = new DataInputStream(new FileInputStream(NomFichierP));
	
		byte bitI=0;
	  	byte bitP=0;
	  	byte n = 0;
	  	boolean eof = false;
		while(!eof)
		{
			try
			{
				bitI = entree.readByte();
				bitP = pass.readByte();
				
			}
			catch(EOFException e)
			{
				eof = true;
			}
			
			if(!eof)
				{
				bitI= (byte)(bitI^bitP);
				 
				n = (byte)(~bitI);
				
				sortie.writeByte(n);
			     	}
		}
		pass.close();
	}
	entree.close();
	
	sortie.close();
	}
}}

Conclusion :


Inconvénient bien sur, une seule clef par cryptage ! (j'y travaille)
Et bien sur une interface minimaliste. Mais bon, le code est léger parce qu'avec des GridBagLayout .... on en rajoute bien des tartines !

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.