Exemple #1
0
        private static void Main(string[] args)
        {
            var cipherText = new B64(File.ReadAllText(@"..\..\..\data.txt")).GetBytes();
            var key        = new Readable("YELLOW SUBMARINE").GetASCIIBytes();

            Console.WriteLine("Decrypted text:");
            Console.WriteLine(Decrypt(cipherText, key));
        }
Exemple #2
0
        public static string ByteArrayToBase64(byte[] ByteArray, bool Urlsafe = true)
        {
            string B64;

            B64 = System.Convert.ToBase64String(ByteArray);
            if (Urlsafe)
            {
                B64 = B64.TrimEnd('=').Replace('+', '-').Replace('/', '_');
            }
            return(B64);
        }
        async Task MakePredictionRequest(MediaFile file)
        {
            Contract.Ensures(Contract.Result <Task>() != null);
            //var client = new HttpClient();

            //client.DefaultRequestHeaders.Add("Prediction-Key", "2596b2fb91e34f07b738da9bd906e5ef");

            string url = "http://222.155.102.53:10008/receiveFile?";

            Debug.WriteLine("hi");


            byte[] byteData    = GetImageAsByteArray(file);
            String b64_data    = Convert.ToBase64String(byteData);
            B64    b64_class   = new B64(b64_data);
            var    payload     = JsonConvert.SerializeObject(b64_class);
            var    httpContent = new StringContent(payload, Encoding.UTF8, "application/json");

            using (var httpClient = new HttpClient())
            {
                //content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                try
                {
                    await httpClient.PostAsync(url, null);

                    var response = await httpClient.PostAsync(url, httpContent);

                    if (response.Content != null)
                    {
                        var responseContent = await response.Content.ReadAsStringAsync();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unknown Exception Thrown: "
                                        + "\n  Type:    " + ex.GetType().Name
                                        + "\n  Message: " + ex.Message);
                }
                Debug.WriteLine("making request....");



                //Get rid of file once we have finished using it
                file.Dispose();
            }
        }
Exemple #4
0
        public static Texture2D Get(string s)
        {
            if (icons == null)
            {
                icons = new Dictionary <string, Texture2D>();
            }
            bool load = false;

            if (!icons.ContainsKey(s))
            {
                load = true;
            }
            else if (icons[s] == null)
            {
                load = true;
            }
            if (load)
            {
                for (int i = 0; i < SharedEmbed.num; i++)
                {
                    if (SharedEmbed.n[i] != s)
                    {
                        continue;
                    }
                    var bb = B64.Decode("iVBORw0KGgoAAAAN" + SharedEmbed.i[i]);
                    var t  = new Texture2D(SharedEmbed.x[i], SharedEmbed.y[i]);
                    t.LoadImage(bb);
                    t.hideFlags |= HideFlags.DontUnloadUnusedAsset;
                    if (icons.ContainsKey(s))
                    {
                        icons[s] = t;
                    }
                    else
                    {
                        icons.Add(SharedEmbed.n[i], t);
                    }
                }
            }
            return(icons[s]);
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            const int maxKey    = 40;
            const int precision = 1;
            var       text      = new B64
                                      (File.ReadAllText(@"..\..\..\data.txt")).GetBytes();
            var textSpan   = new ReadOnlySpan <byte>(text);
            var keyGuesses = new List <KeySizeGuess>();

            for (var keysize = 2; keysize < maxKey + 1; keysize++)
            {
                var sum = 0D;
                for (var i = 0; i < precision * 2; i += 2)
                {
                    var first  = textSpan.Slice(precision * keysize, keysize);
                    var second = textSpan.Slice((precision + 1) * keysize, keysize);
                    sum += (double)HammingDistance(first.ToArray(), second.ToArray()) / keysize;
                }

                var avg = sum / precision;
                keyGuesses.Add(new KeySizeGuess
                {
                    KeySize = keysize,
                    Scoring = avg
                });
            }

            keyGuesses.Sort((a, b) => a.Scoring.CompareTo(b.Scoring));
            var checkedKeys = keyGuesses.Take(5).ToList();
            //Console.WriteLine($"Checked key sizes: {string.Join(',', checkedKeys.Select(k => k.KeySize))}");

            var readables = new List <Readable>();

            foreach (var checkedKey in checkedKeys)
            {
                readables.Add(SolveCipherForKeysize(text, checkedKey));
            }
            Console.WriteLine("Found text:");
            Console.WriteLine(readables.Aggregate((agg, next) => next.Scoring > agg.Scoring ? next : agg).String);
        }
Exemple #6
0
        public void Base64Test1()
        {
            string risposta = B64.Base64();

            Assert.AreEqual("THVjcmV6aWE=", risposta);
        }