Skip to content

Instantly share code, notes, and snippets.

@QuantumHawk
Created March 5, 2015 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuantumHawk/f3bdbdae626a5463f24e to your computer and use it in GitHub Desktop.
Save QuantumHawk/f3bdbdae626a5463f24e to your computer and use it in GitHub Desktop.
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