Answer to Question #319602 in C# for Endinako

Question #319602

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

1
Expert's answer
2022-03-28T11:00:45-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