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.
Marks allocation
1. The programme should received a string " How are you Isaac " - 10
2. The programme should generate an OTP of the length of the string entered "How are you Isaac "- 10
3. The program should Generate a Ciphertext based on the above example- 30
using System;
class ConsoleApp
{
  static void Main()
  {
    Console.Write("Enter the message: ");
    string str = Console.ReadLine() ?? "";
    Console.Write("Enter the 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($"Encrypted message: {ans}");
  }
}
Comments
Leave a comment