Advertisement
oona

encryption

Jan 9th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. public class encryption {
  2.  
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.        
  6.         //inputs
  7.         String originalSentence;
  8.         String convertion = "";
  9.         int asciiCode = 0;
  10.        
  11.         //go through original sentence and add ASCII code to encrypt each character
  12.         //add 3 to each character to attach them in the encrypted sentence
  13.         System.out.println("Please write down your sentence");
  14.         originalSentence = TextIO.getln(); //accept choice as String
  15.        
  16.         for(int i=0; i<originalSentence.length(); i++)
  17.         {  
  18.             asciiCode = (int) (originalSentence.charAt(i));
  19.             asciiCode+=3;
  20.             convertion = convertion + Character.toString((char)asciiCode);
  21.         }
  22.        
  23.        
  24.         System.out.println("Original sentence is converted to " + convertion);
  25.  
  26.        
  27.         //set original sentence to blank
  28.         originalSentence = "";
  29.        
  30.         //decrypt the jumbled sentence
  31.         //subtract 3 from each character and attach them to the sentence
  32.         for(int i=0; i<convertion.length(); i++)
  33.         {
  34.             asciiCode = (int) (convertion.charAt(i));
  35.             asciiCode -=3;
  36.             originalSentence = originalSentence + Character.toString((char)asciiCode);
  37.         }
  38.        
  39.        
  40.         System.out.println("Sentence converted back to original: " + originalSentence);
  41.    
  42.        
  43.     }//class ends
  44.  
  45. }//program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement