Answer to Question #316592 in C# for skillie

Question #316592

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

1
Expert's answer
2022-03-23T13:44:52-0400
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}");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS