Added all files
commit
7cd21cb690
|
@ -0,0 +1,18 @@
|
|||
# cipherplane
|
||||
|
||||
> John Hammond | February 4th, 2018
|
||||
|
||||
------------------------
|
||||
|
||||
This is a project based off of my reaction to the "[DES]" [challenge](https://amritabi0s.wordpress.com/2018/02/03/sharif-ctf-2018-crypto-writeups/) during SharifCTF 2018.
|
||||
|
||||
The [DES] challenge offered about a thousand known plaintext/ciphertext pairs, and asked you to determine the key to submit as the flag. The real difficulty in this challenge was just __sorting through the pairs to find duplicates or similarities in the pairs.__ Had we found one single similarity in a plaintext or ciphertext, we would have been able to find a lead on the challenge and probably solve it.
|
||||
|
||||
But, we didn't have anything that would smartly detect duplicates or similarities in the data. I tossed the challenge aside and never completed it during the competition, but after [reading the writeups](https://ctftime.org/task/5215) I realized we seriously needed that capability.
|
||||
|
||||
So this is just some [Python] code to do that. It doesn't have support for command-line arguments or anything fancy... I expect dirty usage, just slapping in your own data for the script. _It will still get you the information you need._
|
||||
|
||||
The project is nicknamed *`cipherplane`*, as a gag off of "ciphertext" and "plaintext."
|
||||
|
||||
[DES]: https://en.wikipedia.org/wiki/Data_Encryption_Standard
|
||||
[Python]: https://www.python.org/
|
|
@ -0,0 +1,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)
|
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Loading…
Reference in New Issue