-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (59 loc) · 2.26 KB
/
Program.cs
File metadata and controls
67 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using BlowFishCS;
namespace cryptool.net
{
class Program
{
private Thread workerThread;
private SynchronizationContext context;
public event EventHandler SomethingHappened;
private static long keyCount =0;
private static DateTime start= DateTime.Now;
static void Main(string[] args)
{
BlowFish b = new BlowFish("8C56905D8B");
string plainText = "Hello";
string cipherText = b.Encrypt_ECB(plainText);
cipherText = "57E5B6A79048A19B";
Console.WriteLine(cipherText);
plainText = b.Decrypt_ECB(cipherText);
Console.WriteLine(plainText);
int keyLength = 5; //bytes
Crack(cipherText, keyLength, new byte[] { });
Console.WriteLine("done");
}
static void Crack(string cipherText, int keylength, byte[] currentKey)
{
if (keylength == currentKey.Length)
{
BlowFish b = new BlowFish(currentKey);
string plainText = b.Decrypt_ECB(cipherText);
if (plainText.StartsWith("Hello"))
Console.WriteLine("plaintext:" + plainText+", key:"+BitConverter.ToString(currentKey));
keyCount++;
if (keyCount % 10240 == 0)
{
TimeSpan elapsed = DateTime.Now.Subtract(start);
long keyrate = 0;
if (elapsed.Seconds > 0) keyrate = (keyCount / elapsed.Seconds);
Console.WriteLine((keyCount / 1099511627776).ToString() + "%, seconds:" + elapsed.Seconds.ToString() + ", " + keyrate.ToString() + "keys/s ->" + BitConverter.ToString(currentKey));
}
}
else
{
byte[] key = new byte[currentKey.Length+1];
Array.Copy(currentKey,key,currentKey.Length);
for (int i = 0; i < 256; i++)
{
key[key.Length-1] = (byte)i;
Crack(cipherText, keylength, key);
}
}
}
}
}