-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonoAlphabeticCipher
More file actions
50 lines (42 loc) · 1.7 KB
/
MonoAlphabeticCipher
File metadata and controls
50 lines (42 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package monoalphabeticcipher;
import sun.security.pkcs11.wrapper.CK_DATE;
/**
*
* @author Md Ali Shaikh
*/
public class MonoAlphabeticCipher {
public static String ALPHABET ="abcdefghijklmnopqrstuvwxyz";
public static String cryptoAlpha="abcdefghijklmnopqrstuvwxyz";
public static String cryptoKey = "";
public String getCipheredText(String plainText,String key){
plainText=plainText.toLowerCase();
key=key.toLowerCase();
String cipheredText = "";
cryptoAlpha = key + cryptoAlpha;
char[] chars = cryptoAlpha.toCharArray();
int len = chars.length;
for (int i = 0; i < len; i++) {
String ch = String.valueOf(chars[i]);
if(!cryptoKey.contains(ch)){
cryptoKey += ch;
}
}
for (int k = 0; k < plainText.length(); k++) {
char plainChar = plainText.charAt(k);
int index = ALPHABET.indexOf(plainChar);
char ch = cryptoKey.charAt(index);
cipheredText += ch;
}
return cipheredText;
}
public static void main(String[] args) {
MonoAlphabeticCipher mac = new MonoAlphabeticCipher();
String key = "goodboy", plainText = "alishaikh";
String cipheredText = mac.getCipheredText(plainText, key);
System.out.println(ALPHABET.toUpperCase());
System.out.println("cryptoKey: "+cryptoKey+" : "+cryptoKey.length());
System.out.println("Key: "+key);
System.out.println("plainText: "+plainText);
System.out.println("ciphereText: "+cipheredText);
}
}