Created
December 20, 2015 13:45
-
-
Save iamareebjamal/e7fa93ee7b7137f4e5d8 to your computer and use it in GitHub Desktop.
An extremely lolly easy encryption algorithm by Amogh Kulkarni
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Amigho | |
{ | |
public static boolean isUpper(char c){ | |
return (c>='A'&&c<='Z'); | |
} | |
public static boolean isLower(char c){ | |
return (c>='a'&&c<='z'); | |
} | |
/*Encrypt*/ | |
public static String reverse(String s){ | |
char ub, lb; | |
StringBuilder sb = new StringBuilder(); | |
for(char c : s.toCharArray()){ | |
ub = isUpper(c)?'Z':'z'; | |
lb = isUpper(c)?'A':'a'; | |
sb.append((char)(ub+lb-c)); | |
} | |
return sb.toString(); | |
} | |
public static String ascii(String s){ | |
StringBuilder sb = new StringBuilder(); | |
for(char c : s.toCharArray()){ | |
sb.append((int)c+420); | |
} | |
return sb.toString(); | |
} | |
public static String rotate(String s,int n){ | |
StringBuilder sb = new StringBuilder(s); | |
for(;n>0;n--){ | |
sb.insert(0, sb.charAt(sb.length()-1)); | |
sb.deleteCharAt(sb.length()-1); | |
} | |
return sb.toString(); | |
} | |
public static String encrypt(String s){ | |
return rotate(ascii(reverse(s)), 13); | |
} | |
/*Decryption*/ | |
public static String deascii(String s){ | |
StringBuilder sb = new StringBuilder(); | |
for(int i = 0; i <=s.length()-3; i+=3){ | |
sb.append((char)(Integer.parseInt(s.substring(i,i+3))-420)); | |
} | |
return sb.toString(); | |
} | |
public static String derotate(String s,int n){ | |
StringBuilder sb = new StringBuilder(s); | |
for(;n>0;n--){ | |
sb.insert(sb.length(), sb.charAt(0)); | |
sb.deleteCharAt(0); | |
} | |
return sb.toString(); | |
} | |
public static String decrypt(String s){ | |
return reverse(deascii(derotate(s,13))); | |
} | |
public static void main(String[] args) | |
{ | |
Scanner input = new Scanner(System.in); | |
String s = input.nextLine(); | |
System.out.println("String : "+s); | |
System.out.println("\nEncryption:\n"); | |
System.out.println(s); | |
System.out.println("Reversed : "+reverse(s)); | |
System.out.println("ASCII+ : "+ascii(reverse(s))); | |
s = encrypt(s); | |
System.out.println("Rotated : "+s+" (Encrypted)"); | |
System.out.println("\nDecryption:\n"); | |
System.out.println(s); | |
System.out.println("DeRotated : "+derotate(s,13)); | |
System.out.println("DeASCII : "+deascii(derotate(s,13))); | |
System.out.println("Reversed : "+decrypt(s)+" (Decrypted)"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment