Skip to content

Instantly share code, notes, and snippets.

@ShawkyZ
Last active August 29, 2015 14:09
Show Gist options
  • Save ShawkyZ/f6f4c954e110c7a256d6 to your computer and use it in GitHub Desktop.
Save ShawkyZ/f6f4c954e110c7a256d6 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//Get The Encrypted Text And Split them at (.) To Any Array
StreamReader sr = new StreamReader("raw.txt");
string raw = sr.ReadToEnd().Replace("\n","").Replace("\r","");
sr.Close();
string[] raw2 = raw.Split('.');
//Now I Just Assumed that the maximum key sum is 1300 so I'll loop from 32 to 1300
for (int i = 32; i < 1300; i++)
{
string msg = "";
int countindexes = 1;
int firstindex = 1;
//Here I'll Start Sum Every 3 Elements in the array to get the sum and Substract them from the suggested key value which is (i) value
for (int j = 1; j < raw2.Length; j++)
{
int charsum = 0;
if (countindexes==3)
{
for (int k = firstindex; k <= j; k++)
{
charsum += int.Parse(raw2[k]);
}
if ((charsum-i) > 127) //Check if the sum has a real character in the ascii table
break;
firstindex = j+1;
msg += (char)(charsum-i);
countindexes = 0;
}
countindexes++;
}
//Now We'll Check if the Decrypted Text has the word Samuel Or Not , If it doesn't so the key we suggested isn't true and we'll try again.
if (msg.Contains("Samuel"))
{
StreamWriter sw = new StreamWriter("finalmsg.txt");
sw.WriteLine(msg);
sw.Close();
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment