Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1.  
  2.  
  3. package javaapplication1;
  4.  
  5. /**
  6.  *
  7.  * @author Danny
  8.  */
  9.  
  10. //import scanner//
  11. import java.util.Scanner;
  12. public class Main {
  13.  
  14.  
  15.    
  16.     public static void main(String[] args)
  17.     {
  18.  
  19.         //Variables//
  20.     int orig;
  21.         int result;
  22.     int digit1, digit2, digit3,digit4;
  23.     int number = 0;
  24.  
  25.         //Import scanner, here, and above.//
  26.         System.out.print("Enter a four digit number: ");
  27.         Scanner keyboard = new Scanner(System.in);
  28.         orig = keyboard.nextInt();
  29.  
  30.         //I used a do-while statement.
  31.         do {
  32.  
  33.             // Code for encryption//
  34.  
  35.         //For the first digit, this will be applied//
  36.         orig = orig % 1000;
  37.         orig= orig + 7;
  38.         digit1 = orig % 10;
  39.  
  40.  
  41.         //For the second digit, this will be applied//
  42.         orig = orig % 1000;
  43.         orig = orig % 100;
  44.         orig = orig+7;
  45.         digit2 = orig % 10;
  46.  
  47.  
  48.         //For the third digit, this will be applied//
  49.        
  50.         orig = orig % 10;
  51.         orig = orig+7;
  52.         digit3 = orig % 10;
  53.  
  54.  
  55.         //For the fourth digit, this will be applied//
  56.        
  57.         orig = orig+7;
  58.         digit4 = orig % 10;
  59.  
  60.             //Swap first and third digits//
  61.             digit2 = digit4;
  62.             digit1 = digit3 * 1000;
  63.             digit3 = orig * 10;
  64.  
  65.             //Swap second and fourth digit//
  66.             orig = digit2;
  67.             digit2 = digit4 * 100;
  68.             digit4 = orig;
  69.  
  70.             //The result is//
  71.             result = digit1 + digit2 + digit3
  72.                     + digit4 ;
  73.  
  74.             //Print the result (Encrpted number)//
  75.             System.out.println("The Encrypted number is:" +result);
  76. } while (number>0);
  77.  
  78.     }
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement