Create a program using C# that implements the stream ciphers Cryptographic method . A stream cipher method inputs digits, bits, or characters and encrypts the stream of data. The onetime pad is an example of a stream cipher.
In this formative you have been requested to create an application that will work as the One-time pad (OTP), also called Vernam-cipher or the perfect cipher. This is a crypto algorithm where plaintext is combined with a random key and generate a ciphertext
using System;
class Encryption
{
static void Main()
{
Console.Write("message > ");
string str = Console.ReadLine() ?? "";
Console.Write("key > ");
string key = Console.ReadLine() ?? "";
int mod = key.Length;
int j = 0;
for (int i = key.Length; i < str.Length; i++)
{
key += key[j % mod];
j++;
}
string ans = "";
for (int i = 0; i < str.Length; i++)
ans += Convert.ToChar((key[i] - 'A' + str[i] - 'A') % 26 + 'A');
Console.WriteLine($"encryption > {ans}");
}
}
Comments
Leave a comment