forked from JohnHammond/cipherplane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cipherplane.py
executable file
·75 lines (54 loc) · 2.25 KB
/
cipherplane.py
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
68
69
70
71
72
73
74
75
#!/usr/bin/env python
from colorama import *
import collections
'''
We need to know...
1. if there are duplicates in the plaintext
2. if there are duplicates in the ciphertext
3. if there are entries in the plaintext that are in the ciphertext
4. if there are entries in the ciphertext that are in the plaintext
'''
def G(string): return Style.BRIGHT + Fore.GREEN + string + Fore.RESET + Style.NORMAL
def g(string): return Fore.GREEN + string + Fore.RESET
def B(string): return Style.BRIGHT + Fore.BLUE + string + Fore.RESET + Style.NORMAL
def b(string): return Fore.BLUE + string + Fore.RESET
def Y(string): return Style.BRIGHT + Fore.YELLOW + string + Fore.RESET + Style.NORMAL
def y(string): return Fore.YELLOW + string + Fore.RESET
def C(string): return Style.BRIGHT + Fore.CYAN + string + Fore.RESET + Style.NORMAL
def c(string): return Fore.CYAN + string + Fore.RESET
def get_duplicates( entries ):
counted_entries = collections.Counter(entries)
duplicates = { item : count for item, count in counted_entries.items() if count > 1 }
return duplicates
def print_duplicates(entries):
duplicates = get_duplicates(entries)
number_duplicates = len(duplicates.keys())
if number_duplicates > 0:
print g("\n[!] There are "+ G(str(number_duplicates)) +" duplicates!")
index = 1
for duplicate, count in duplicates.iteritems():
print y("["+str(index)+"] " ) + Y(str(duplicate)) + y(" duplicated ") + G(str(count)) + y(" times!")
index += 1
print "\n"
def get_similarities( a, b ):
return list(set(a).intersection(set(b)))
def print_similarities( a, b ):
similarities = get_similarities(a, b)
number_similarities = len(similarities)
if number_similarities > 0:
print g("\n[!] There are ") + G(str(number_similarities)) + g(" same entries in the two sets!")
index = 1
for similarity in similarities:
print y("["+str(index)+"] " ) + Y(str(similarity))
index += 1
print "\n"
def process( plaintext, ciphertext ):
print C("Processing plaintext...")
print_duplicates(plaintext)
print C("Processing ciphertext...")
print_duplicates(ciphertext)
print C("Processing plaintext and ciphertext...")
print_similarities( plaintext, ciphertext )
plaintext = range(1, 10) + range(1, 4)
ciphertext = [ x**2 for x in range(1,10) ]
process(plaintext, ciphertext)