One time pad, encryption and decryption

后端 未结 6 1818
-上瘾入骨i
-上瘾入骨i 2021-01-17 23:34

I am trying to pick up cryptography and had been trying this exercise

Write a program (preferably Java) to generate a one-time pad, which is a relatively large file

6条回答
  •  礼貌的吻别
    2021-01-17 23:54

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace one_time_pad
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("                   TRYING\n");
    
                Console.WriteLine("Enter : ");
                int input= int.Parse( Console.ReadLine());
    
                //random num generation
                Random rnd = new Random();
                int random = rnd.Next(1,10);
    
                //binary conversion
                string binary = Convert.ToString(random,2);
                string inbinary = Convert.ToString(input,2);
    
                Console.WriteLine("Data :   " +input +"   Binary :   " + inbinary);
                Console.WriteLine(" Key :   " +random + "   Binary :    " + binary);    
    
                // taking xor
                int Ghul = input ^ random;
    
                //binary conversion
                string intcon = Convert.ToString(Ghul,2);
    
                Console.WriteLine("Encrypted : " + intcon);
    
                Console.WriteLine(":)");
    
                Console.Read();    
            }
        }
    }
    

提交回复
热议问题