Ejemplo n.º 1
0
        public Task <IActionResult> DecipherRSA([FromForm] RSARequest obj)
        {
            if (obj.File.Length > 0)
            {
                if (!Directory.Exists(_environment.WebRootPath + "\\Cipher2\\"))
                {
                    Directory.CreateDirectory(_environment.WebRootPath + "\\Cipher2\\");
                }
                using var _fileStream = System.IO.File.Create(_environment.WebRootPath + "\\Cipher2\\" + obj.File.FileName);
                obj.File.CopyTo(_fileStream);
                _fileStream.Flush();
                _fileStream.Close();
                string FilePublic = "PublicKey.txt";

                if (!Directory.Exists(_environment.WebRootPath + "\\Cipher2\\"))
                {
                    Directory.CreateDirectory(_environment.WebRootPath + "\\Cipher2\\");
                }
                using var _fileStreamPublic = System.IO.File.Create(_environment.WebRootPath + "\\Cipher2\\" + FilePublic);
                _fileStreamPublic.Flush();
                _fileStreamPublic.Close();

                caesar.Decipher(_environment.WebRootPath + "\\Cipher2\\" + obj.File.FileName, rsa.GeneratePublicKey(obj.P, obj.Q, obj.Key, _environment.WebRootPath + "\\Cipher2\\" + FilePublic), _environment.WebRootPath + "\\Cipher2\\" + obj.Name + ".txt");
                return(DownloadZIP());
            }

            return(null);
        }
Ejemplo n.º 2
0
    private void ClientConnected(object sender, Server.ClientConnectedEventArgs e)
    {
        Console.WriteLine("Client connected");
        var caesar = new Caesar {
            Alphabet = "abcdefghijklmnopqrstuvwxyzåäö",
            Shift    = 0
        };

        using (var stream = e.Client.GetStream())
            using (var reader = new StreamReader(stream, Encoding.UTF8))
                using (var writer = new StreamWriter(stream, Encoding.UTF8)) {
                    while (!reader.EndOfStream)
                    {
                        var received = reader.ReadLine();

                        for (caesar.Shift = 0; caesar.Shift < caesar.Alphabet.Length; caesar.Shift++)
                        {
                            writer.WriteLine(caesar.Decipher(received));
                        }

                        writer.WriteLine();
                        writer.Flush();
                    }
                }

        e.Client.Close();

        Console.WriteLine("Client disconnected");
    }
Ejemplo n.º 3
0
        public void Decipher()
        {
            var inputString    = "Åcglsftfzzf vkvålåhhu ucrcffu zvzphhspzääååh qh rcrcf lzppuåcf åhp hpuhrpu åhyöpååhlzzh wpåff äzrhsåhh höhåh zääuzh rvrvärzpzzh.";
            var expectedString = "Työelämässä odotetaan nykyään sosiaalisuutta ja kykyä esiintyä tai ainakin tarvittaessa pitää uskaltaa avata suunsa kokouksissa.";
            var caesar         = new Caesar {
                Alphabet = "abcdefghijklmnopqrstuvwxyzåäö",
                Shift    = 7
            };
            var returnedString = caesar.Decipher(inputString);

            Assert.True(expectedString == returnedString, "The input string was not deciphered correctly. " + returnedString);
        }
Ejemplo n.º 4
0
        public Task <IActionResult> DecipherCaesar([FromForm] CipherCaesarRequest DecipherCaesarRequest)
        {
            if (DecipherCaesarRequest.File.Length > 0)
            {
                if (!Directory.Exists(_environment.WebRootPath + "\\Decipher\\"))
                {
                    Directory.CreateDirectory(_environment.WebRootPath + "\\Decipher\\");
                }
                using var _fileStream = System.IO.File.Create(_environment.WebRootPath + "\\Decipher\\" + DecipherCaesarRequest.File.FileName);
                DecipherCaesarRequest.File.CopyTo(_fileStream);
                _fileStream.Flush();
                _fileStream.Close();

                CaesarCipher.Decipher(_environment.WebRootPath + "\\Decipher\\" + DecipherCaesarRequest.File.FileName, DecipherCaesarRequest.Key, _environment.WebRootPath + "\\Decipher\\" + DecipherCaesarRequest.Name + ".txt");
                return(GetFile(Convert.ToString(DecipherCaesarRequest.Name), "\\Decipher\\"));
            }

            return(null);
        }