Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.IO;
- using System.Linq;
- using System.Text;
- class Nice {
- static string[] symbols = new String[] { " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "/", "*", "=", "^", "%", ".", ",", ":" };
- static string changeWord(string str) {
- bool[] buk = new bool[28];
- string res = "";
- for (int i = 0; i < str.Length; i++) {
- int ch = Char.ToLower(str[i]) - 'a';
- if (!buk[ch]) {
- res += str[i];
- buk[Char.ToLower(str[i]) - 'a'] = true;
- }
- }
- return res;
- }
- static Encoding encoding = Encoding.ASCII;
- static byte[] crypt(string text, string keying) {
- byte[] plainText = encoding.GetBytes(text);
- byte[] key = encoding.GetBytes(keying);
- // encrypt: key XOR plainText
- byte[] cipherText = new byte[plainText.Length];
- new BitArray(key).Xor(new BitArray(plainText)).CopyTo(cipherText, 0);
- // decrypt: key XOR chipherText
- //byte[] decripted = new byte[cipherText.Length];
- //new BitArray(key).Xor(new BitArray(cipherText)).CopyTo(decripted, 0);
- return /*encoding.GetString(*/cipherText/*)*/;
- }
- static byte[] cryptBytes(byte[] plainText, byte[] key) {
- // encrypt: key XOR plainText
- byte[] cipherText = new byte[plainText.Length];
- new BitArray(key).Xor(new BitArray(plainText)).CopyTo(cipherText, 0);
- // decrypt: key XOR chipherText
- //byte[] decripted = new byte[cipherText.Length];
- //new BitArray(key).Xor(new BitArray(cipherText)).CopyTo(decripted, 0);
- return /*encoding.GetString(*/cipherText/*)*/;
- }
- static byte[] bt(byte b) {
- return new Byte[] { b };
- }
- public static string HextoString(string InputText) {
- byte[] bb = Enumerable.Range(0, InputText.Length)
- .Where(x => x % 2 == 0)
- .Select(x => Convert.ToByte(InputText.Substring(x, 2), 16))
- .ToArray();
- return System.Text.Encoding.ASCII.GetString(bb);
- // or System.Text.Encoding.UTF7.GetString
- // or System.Text.Encoding.UTF8.GetString
- // or System.Text.Encoding.Unicode.GetString
- // or etc.
- }
- public static byte[] HextoBytes(string InputText) {
- byte[] bb = Enumerable.Range(0, InputText.Length)
- .Where(x => x % 2 == 0)
- .Select(x => Convert.ToByte(InputText.Substring(x, 2), 16))
- .ToArray();
- return bb;
- }
- static string twoSybm(string str) {
- return (str.Length == 1 ? "0" + str : str);
- }
- static string ToHexString(byte[] hexstring) {
- StringBuilder sb = new StringBuilder();
- foreach (char t in hexstring) {
- //Note: X for upper, x for lower case letters
- sb.Append(Convert.ToInt32(t).ToString("x"));
- }
- return twoSybm(sb.ToString());
- }
- static string printHex(string hex) {
- string res = "";
- for (int i = 0; i < hex.Length; i++) {
- if (i != 0 && i % 2 == 0)
- res += " ";
- res += hex[i];
- }
- return res;
- }
- static void Main(string[] args) {
- /*byte[] text = HextoBytes("315c4eeaa8b5f8aaf9174145bf43e1784b8fa00dc71d885a804e5ee9fa40b16349c146fb778cdf2d3aff021dfff5b403b510d0d0455468aeb98622b137dae857553ccd8883a7bc37520e06e515d22c954eba5025b8cc57ee59418ce7dc6bc41556bdb36bbca3e8774301fbcaa3b83b22");
- byte[] keying = HextoBytes("234c02ecbbfbafa3ed18510abd11fa724fcda2018a1a8342cf064bbde548b12b07df44ba7191d9606ef4081ffde5ad46a5069d9f7f543bedb9c861bf29c7e205132eda9382b0bc2c5c4b45f919cf3a9f1cb74151f6d551f4480c82b2cb24cc5b028aa76eb7b4ab24171ab3cdadb8356f");
- byte[] crypted = cryptBytes(text, keying);
- */
- //byte[] text = encoding.GetBytes("abcdefghijklmnopqrstuvwxyz"); //with spaces 65-90 for a-z
- byte[] text = encoding.GetBytes("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //with spaces 97-122 for A-Z
- byte[] keying = encoding.GetBytes("..........................");
- byte[] crypted = cryptBytes(text, keying);
- byte[] text1 = HextoBytes("315c4eeaa8b5f8aaf9174145bf43e1784b8fa00dc71d885a804e5ee9fa40b16349c146fb778cdf2d3aff021dfff5b403b510d0d0455468aeb98622b137dae857553ccd8883a7bc37520e06e515d22c954eba5025b8cc57ee59418ce7dc6bc4");
- byte[] keying1 = HextoBytes("32510ba9a7b2bba9b8005d43a304b5714cc0bb0c8a34884dd91304b8ad40b62b07df44ba6e9d8a2368e51d04e0e7b207b70b9b8261112bacb6c866a232dfe257527dc29398f5f3251a0d47e503c66e935de81230b59b7afb5f41afa8d661cb");
- //byte[] text = HextoBytes("271946f9"); //HextoBytes("32510b");
- //byte[] keying = new Byte[] { 102, 57, 110};//102 57 110 The
- //Разница между заглавными буквами = 32 = 2^8
- byte[] crypted1 = cryptBytes(text1, keying1);
- for (int i = 0; i < Math.Min(text.Length, text1.Length); i++) {
- Console.WriteLine("{0}({1}) xor {2}({3}) = {4}({5}) : {6}({7})", (int)text[i], encoding.GetString(bt(text[i])), (int)keying[i], encoding.GetString(bt(keying[i])), (int)crypted[i], ToHexString(bt(crypted[i])), (int)crypted1[i], ToHexString(bt(crypted1[i])));
- }
- Console.WriteLine("\n Result: \n {0} \n =to= \n {1}", text, encoding.GetString(crypted));
- Console.WriteLine("\n comparing: \n {0} \n =with= \n {1}", printHex(ToHexString(crypted)), printHex(ToHexString(crypted1)));
- //диапазон 0-31
- //заглавная буква +32 к разнице
- //То есть числа > 31 - заглавные буквы
- //Пробел - диапазон от 65-90 (ш16-я с. с. 41-5a)
- //Точка 1-93 с заглавными
- //Точка 0-93 с заглавными
- int max = 0;
- char[] maxi = new char[] { 'A', 'A' };
- int min = int.MaxValue;
- char[] mini = new char[] { 'A', 'A' };
- for (byte i = 0; i < 26; i++) {
- for (byte j = 0; j < 26; j++) {
- char ct = (char)('A' + i);
- char ct2 = (char)('a' + j);
- byte[] cry = crypt(Char.ToString(ct), Char.ToString(ct2));
- if (cry[0] >= max) {
- max = cry[0];
- maxi = new char[] { ct, ct2 };
- }
- if (cry[0] <= min) {
- min = cry[0];
- mini = new char[] { ct, ct2 };
- }
- }
- }
- Console.WriteLine("MAX: " + max + " = " + maxi[0] + " xor " + maxi[1]);
- Console.WriteLine("MIN: " + min + " = " + mini[0] + " xor " + mini[1]);
- //Console.WriteLine(HextoString("32510ba9babebbbefd001547a810e67149caee11d945cd7fc81a05e9f85aac650e9052ba6a8cd8257bf14d13e6f0a803b54fde9e77472dbff89d71b57bddef121336cb85ccb8f3315f4b52e301d16e9f52f904") + " - eto");
- Console.ReadKey();
- }
- }
- /*
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class Nice {
- static string[] symbols = new String[] { " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "/", "*", "=", "^", "%", ".", ",", ":" };
- static string changeWord(string str) {
- bool[] buk = new bool[28];
- string res = "";
- for (int i = 0; i < str.Length; i++) {
- int ch = Char.ToLower(str[i]) - 'a';
- if (!buk[ch]) {
- res += str[i];
- buk[Char.ToLower(str[i]) - 'a'] = true;
- }
- }
- return res;
- }
- static void Main(string[] args) {
- string[] lines = File.ReadAllLines("input.txt");
- string[] lastline = Array.ConvertAll((lines[lines.Length - 1]).Split(symbols, StringSplitOptions.RemoveEmptyEntries), changeWord);
- foreach (string line in lines) {
- string[] words = Array.ConvertAll(line.Split(symbols, StringSplitOptions.RemoveEmptyEntries), changeWord);
- foreach (string str in words)
- if (str != lastline[lastline.Length - 1])
- Console.Write(str + " ");
- }
- Console.ReadKey();
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement