コード例 #1
0
ファイル: Test.cs プロジェクト: WojciechSzweda/CSST
        public static void DES_ECBtest()
        {
            var name = "sam";
            var key  = DEShelper.GenerateRandomData().ToList();

            des.EncryptImage($"{name}.png", key, $"encrypted{name}.png");
            des.DecryptImage($"encrypted{name}.png", key, $"decrypted{name}.png");
        }
コード例 #2
0
ファイル: LSB.cs プロジェクト: WojciechSzweda/CSST
        public static string DecryptTextFromImage(string path, int length)
        {
            var img       = new Bitmap(path);
            var pixels    = DEShelper.GetPixels(img).ToArray();
            var binOutput = new List <int>();

            for (int i = 0; i < 8 * length; i++)
            {
                binOutput.Add(GetLastBit(pixels[i].R));
            }
            return(DEShelper.BinaryToText(binOutput.ListToString()));
        }
コード例 #3
0
ファイル: LSB.cs プロジェクト: WojciechSzweda/CSST
        public static void EncryptInImage(string path, string input)
        {
            var img      = new Bitmap(path);
            var pixels   = DEShelper.GetPixels(img).ToArray();
            var binInput = DEShelper.TextToBinary(input).ToArray();

            for (int i = 0; i < binInput.Count(); i++)
            {
                img.SetPixel(i % img.Width, i / img.Width, Color.FromArgb(pixels[i].A, ChangeByte(pixels[i].R, binInput[i]), pixels[i].G, pixels[i].B));
            }
            img.Save($"encrypted{path}");
        }
コード例 #4
0
ファイル: Test.cs プロジェクト: WojciechSzweda/CSST
        public static void DES_OFBtest()
        {
            var vector = DEShelper.GenerateRandomData().ToList();
            var key    = DEShelper.GenerateRandomData().ToList();

            var name = "blocksOFB";

            DEShelper.GenerateRandomDataBlocks($"{name}.txt", 8);
            var ofbE = des.OFB(DEShelper.GetDataBlocksFromFile($"{name}.txt"), key, vector);

            DEShelper.SaveBlocksToFile($"{name}encrypted.txt", ofbE);
            var ofbD = des.OFB(DEShelper.GetDataBlocksFromFile($"{name}encrypted.txt"), key, vector);

            DEShelper.SaveBlocksToFile($"{name}decrypted.txt", ofbD);
        }
コード例 #5
0
ファイル: Test.cs プロジェクト: WojciechSzweda/CSST
        public static void DES_CBCtest()
        {
            var vector = DEShelper.GenerateRandomData().ToList();
            var key    = DEShelper.GenerateRandomData().ToList();

            var name = "blocksCBC";

            DEShelper.GenerateRandomDataBlocks($"{name}.txt", 8);
            var cbcE = des.EncryptCBC(DEShelper.GetDataBlocksFromFile($"{name}.txt"), key, vector);

            DEShelper.SaveBlocksToFile($"{name}encrypted.txt", cbcE);
            var cbcD = des.DecryptCBC(DEShelper.GetDataBlocksFromFile($"{name}encrypted.txt"), key, vector);

            DEShelper.SaveBlocksToFile($"{name}decrypted.txt", cbcD);
        }
コード例 #6
0
ファイル: Test.cs プロジェクト: WojciechSzweda/CSST
        public static void DES_PCBCtest()
        {
            var vector = DEShelper.GenerateZeroOne();
            var key    = DEShelper.GenerateDataByBytes(0, 1);
            var data   = DEShelper.GeneratePreDefArrayBlocks(new int[] { 0, 1, 0 });

            Console.WriteLine($"data:\n{data.BlocksToString()}");
            Console.WriteLine($"\nkey:\n{key.ListToString()}");
            Console.WriteLine($"\nvector:\n{vector.ListToString()}");

            var pcbcE = des.EncryptPCBC(data, key, vector);

            Console.WriteLine($"\nEncrypted:\n{pcbcE.BlocksToString()}");
            var pcbcD = des.DecryptPCBC(pcbcE, key, vector);

            Console.WriteLine($"\nDecrypted:\n{pcbcD.BlocksToString()}");
        }
コード例 #7
0
ファイル: DES.cs プロジェクト: WojciechSzweda/CSST
        public void DecryptImage(string imagePath, IEnumerable <int> key, string outName)
        {
            Console.WriteLine("Decrypting");
            var colors          = DEShelper.GetPixels(imagePath).ToArray();
            var encryptedColors = new List <IEnumerable <int> >();
            var len             = colors.Count();

            for (int i = 0; i < len; i += 2)
            {
                var bin1 = Convert.ToString(Convert.ToInt64(colors[i].Name, 16), 2).PadLeft(32, '0').ToIntList();
                var bin2 = Convert.ToString(Convert.ToInt64(colors[i + 1].Name, 16), 2).PadLeft(32, '0').ToIntList();
                encryptedColors.Add(Decrypt(bin1.Concat(bin2), key).ToList());
            }
            Console.WriteLine("Decrypted\nSaving...");
            DEShelper.SaveImage64x64(encryptedColors, outName);
            Console.WriteLine($"Saved {outName}");
        }
コード例 #8
0
ファイル: Test.cs プロジェクト: WojciechSzweda/CSST
        public static void DES_CTRtest()
        {
            var key     = DEShelper.GenerateDataByBytes(0, 1);
            var data    = DEShelper.GeneratePreDefArrayBlocks(new int[] { 0, 1, 0 });
            var nonce   = DEShelper.GenerateOneZero(32);
            var counter = DEShelper.GeneratePreDefData(32);

            Console.WriteLine($"data:\n{data.BlocksToString()}");
            Console.WriteLine($"\nkey:\n{key.ListToString()}");
            Console.WriteLine($"\nCTR:\n{nonce.ListToString()}{counter.ListToString()}");

            var func         = new Func <int, int>((x) => x + 1);
            var cntFunction  = new Func <IEnumerable <int>, IEnumerable <int> >((input) => DEShelper.BitListOperation(input, (x) => x + 1));
            var cntFunction2 = new Func <IEnumerable <int>, IEnumerable <int> >((input) => DEShelper.BitListOperation(input, (x) => 5 * (x + 1) + 3));

            var ctrE = des.CTR(data, key, nonce, counter, cntFunction);

            Console.WriteLine($"\nEncrypted:\n{ctrE.BlocksToString()}");
            var ctrD = des.CTR(ctrE, key, nonce, counter, cntFunction);

            Console.WriteLine($"\nDecrypted:\n{ctrD.BlocksToString()}");
        }
コード例 #9
0
ファイル: Test.cs プロジェクト: WojciechSzweda/CSST
        public static void DEStest()
        {
            var data = DEShelper.GenerateRandomData().ToList();
            var key  = DEShelper.GenerateRandomData().ToList();

            Console.WriteLine($"data BIN: {data.ListToString()}");
            Console.WriteLine($"data HEX: {data.ToHex()}");
            Console.WriteLine();
            Console.WriteLine($"key BIN: {key.ListToString()}");
            Console.WriteLine($"key HEX: {key.ToHex()}");
            Console.WriteLine();

            var encrypted = des.Encrypt(data, key);

            Console.WriteLine($"encypted BIN {encrypted.ListToString()}");
            Console.WriteLine($"encypted HEX {encrypted.ToHex()}");


            Console.WriteLine();
            var decrypted = des.Decrypt(encrypted, key);

            Console.WriteLine($"decrypted BIN: {decrypted.ListToString()}");
            Console.WriteLine($"decrypted HEX: {decrypted.ToHex()}");
        }