Created
November 28, 2016 19:30
-
-
Save therealshabi/d00a0c1ace52e44cc9919767198ad47f to your computer and use it in GitHub Desktop.
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 Testing | |
{ | |
public static void main(String args[]) | |
{ | |
Scanner in = new Scanner(System.in); | |
String password = in.nextLine(); | |
String key = in.next(); | |
int i; | |
/*key = key.toUpperCase(); | |
//char keys[] = key.toCharArray(); | |
password = password.toUpperCase();*/ | |
int a[] = new int[key.length()]; | |
for(i=0;i<key.length();i++) | |
{ | |
a[i] = key.charAt(i)-33; | |
} | |
char pass[] = password.toCharArray(); | |
int k=0; | |
String ans = ""; | |
for(i=0;i<password.length();i++) | |
{ | |
int temp = (pass[i]+a[k]-33)%94; | |
//System.out.print(temp+" "); | |
pass[i] = (char)(temp+33); | |
k++; | |
while(k==key.length()) | |
{ | |
k=0; | |
} | |
ans+=pass[i]; | |
} | |
System.out.println("Password : "+password); | |
System.out.println("Encrypted Text : "+ans); | |
k=0; | |
ans =""; | |
for(i=0;i<password.length();i++) | |
{ | |
int temp = (pass[i]-a[k]-33); | |
if(temp<0) | |
{ | |
temp+=94; | |
} | |
pass[i] = (char)(temp+33); | |
k++; | |
if(k==key.length()) | |
{ | |
k=0; | |
} | |
ans+=pass[i]; | |
} | |
System.out.println("Decrypted Text : "+ans); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment