VERNER Assignment
VERNER Assignment
USING JAVA
BY
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
In this algorithm, the length of the key should be equal to that of plain text.
Example
INPUT
Key = MONEY
OUTPUT
Plain text — H E L L O → 7 4 11 11 14
Key — M O N E Y → 12 14 13 4 24
→ 19 18 24 15 12 (=38 – 26)
Cipher Text → T S Y P M
Converting the Cipher text to Message:-
Cipher Text — T S Y P M → 19 18 24 15 12
Key — M O N E Y→ 12 14 13 4 24
→ 7 4 11 11 14
Message → H E L L O
Implementing the Vernam cipher encryption algorithm on java using the example
above
package com.fandy;
// Java program Implementing One Time Pad Algorithm
// Main class
public class GFG {
// Method 1
// Returning encrypted text
public static String stringEncryption(String text,
String key) {
// Initializing cipherText
String cipherText = "";
// Method 2
// Returning plain text
public static String stringDecryption(String s,
String key) {
// Initializing plain text
String plainText = "";
// Returning plainText
return plainText;
}
}
Creating another class Hello and then import the GFG.stringDecryption classes
package com.fandy;
OUTPUT RESULT
Message - FAITH
- 'A';
cipherText += (char) x;
return cipherText;
}
public static String stringDecryption(String s, String key)
plain[i]
if (plain[i] < 0) {
plainText += (char) x;
return plainText;
+ encryptedText);
System.out.println(
"Message - "
+ stringDecryption(encryptedText,
key.toUpperCase()));