Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class encryption {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //inputs
- String originalSentence;
- String convertion = "";
- int asciiCode = 0;
- //go through original sentence and add ASCII code to encrypt each character
- //add 3 to each character to attach them in the encrypted sentence
- System.out.println("Please write down your sentence");
- originalSentence = TextIO.getln(); //accept choice as String
- for(int i=0; i<originalSentence.length(); i++)
- {
- asciiCode = (int) (originalSentence.charAt(i));
- asciiCode+=3;
- convertion = convertion + Character.toString((char)asciiCode);
- }
- System.out.println("Original sentence is converted to " + convertion);
- //set original sentence to blank
- originalSentence = "";
- //decrypt the jumbled sentence
- //subtract 3 from each character and attach them to the sentence
- for(int i=0; i<convertion.length(); i++)
- {
- asciiCode = (int) (convertion.charAt(i));
- asciiCode -=3;
- originalSentence = originalSentence + Character.toString((char)asciiCode);
- }
- System.out.println("Sentence converted back to original: " + originalSentence);
- }//class ends
- }//program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement