Created
March 5, 2015 12:19
Revisions
-
QuantumHawk created this gist
Mar 5, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ 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); } }