Created
March 5, 2015 12:19
-
-
Save QuantumHawk/f3bdbdae626a5463f24e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class Cipher { | |
// private int smesh = (int)'a'; | |
String Alph = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; | |
public String enc (String text){ | |
StringBuilder ans = new StringBuilder(); | |
for (int i=0; i<text.length();i++){ | |
String[] m = text.split(""); | |
String element = m[i]; | |
int num = Alph.indexOf(element)+i; | |
char a = (char) Alph.charAt(num); | |
ans.append(a); | |
} | |
return ans.toString(); | |
} | |
public String desc (String s){ | |
StringBuilder san = new StringBuilder(); | |
for (int i=0; i<s.length(); i++){ | |
String[] n = s.split(""); | |
String element = n[i]; | |
int num = Alph.indexOf(element)-i; | |
char a = (char) Alph.charAt(num); | |
san.append(a); | |
} | |
return san.toString(); | |
} | |
public static void main(String[] args) { | |
// TODO code application logic here | |
Scanner scan = new Scanner(System.in, "CP1251"); | |
Cipher mr = new Cipher(); | |
System.out.println("Введите слово\n"); | |
String s = scan.nextLine(); | |
String enc = mr.enc(s); | |
System.out.println("Зашифрованное\n"+enc); | |
String desc = mr.desc(enc); | |
System.out.println("Расшифрованное\n"+desc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment