- 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();
- }
- }}
-
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();
}
}}