Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Strange issue with this is I for some reason can't use any characters in an Encryption code that are going to get //Encrypted be the next Encryption...?!
- import java.io.*;
- import java.util.*;
- /**
- * Write a description of class CryptoTest here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class CryptoTest
- {
- public static void main(String args[])
- {
- //Scanner kbReader = new Scanner(System.in);
- System.out.print("Enter a sentence that is to be encrypted: ");
- String sntnc = "This is a very big morning.";//kbReader.nextLine( );
- System.out.println("Original sentence = " + sntnc);
- MyCrypto myCryptObj = new MyCrypto( );
- String encryptdSntnc = myCryptObj.encrypt2(sntnc);
- System.out.println("Encrypted sentence = " + encryptdSntnc);
- String decryptdSntnc = myCryptObj.decrypt2(encryptdSntnc);
- System.out.println("Decrypted sentence = " + decryptdSntnc);
- }
- /*
- * Enter a sentence that is to be encrypted: This is a very big morning.
- * Original sentence = This is a very big morning.
- * Encrypted sentence = This is a ag',rery dug>?/ijeb..w ssadorninjeb..w.
- * V = ag',r
- * B = dug>?/
- * G = jeb..w
- * M = ssad
- *
- * Decrypted sentence = This is a very big morning.
- *
- *
- */
- }
- import java.io.*;
- import java.util.*;
- /**
- * Write a description of class MyCrypto here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class MyCrypto
- {
- public String MN;
- public String Hold1;
- public String Hold2;
- private String Ch1;
- private String Ch2;
- private String Ch3;
- private String[] Tar = new String[4];
- private String[] Rep = new String[4];
- /**
- * Constructor for objects of class MyCrypto
- */
- public MyCrypto()
- {
- //
- Ch1 = "agfgr";
- Ch2 = "jeb..w";
- Ch3 = "ssad";
- Tar[0] = "v";
- Tar[1] = "g";
- Tar[2] = "m";
- Tar[3] = "b";
- Rep[0] = "g";
- Rep[1] = "v";
- Rep[2] = "b";
- Rep[3] = "m";
- }
- public String encrypt(String E)
- {
- MN = E.replace("v", Ch1);
- Hold1 = MN.replace("g", Ch2);
- MN = Hold1;
- Hold2 = MN.replace("m", Ch3);
- MN = Hold2;
- return MN;
- }
- public String decrypt(String D)
- {
- MN = D;
- Hold1 = MN.replace(Ch2, "g");
- MN = Hold1;
- Hold2 = MN.replace(Ch3, "m");
- MN = Hold2;
- String Test = MN.replace(Ch1, "v");
- MN = Test;
- return MN;
- }
- public String encrypt2(String E)
- {
- MN = E;
- int Run = 0;
- while(Run < 4)
- {
- Hold1 = MN.replace(Tar[Run], Rep[Run]);
- MN = Hold1;
- Run++;
- }
- return MN;
- }
- public String decrypt2(String E)
- {
- MN = E;
- int Run = 0;
- while(Run < 4)
- {
- Hold1 = MN.replace(Rep[Run], Tar[Run]);
- MN = Hold1;
- Run++;
- }
- return MN;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement