Skip to content

Instantly share code, notes, and snippets.

@hribeirosantana
Created May 2, 2019 07:04
Show Gist options
  • Save hribeirosantana/e51c04a353a6ccad630aa11d88fd1a35 to your computer and use it in GitHub Desktop.
Save hribeirosantana/e51c04a353a6ccad630aa11d88fd1a35 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 29 04:25:03 2019
@author: hugo
"""
"""This is a FAILED attempt to solve evilzone's challenge "encryption 2"
"Figure out what this says:
rxzryiyxyion wiqhasr wen za zsoman feislt aerilt, er lonk er yha wiqhas
yauy ir lonk anoxkh, end wonyeinr anoxkh woggonlt xrad whesewyasr."
The attempt assumes various things about the ciphered text (e.g.
the substitution is the same for equal letters, the text is not
reversed, it is in english, etc). The idea was (1) to pick a slice of
the ciphered text (I picked "er lonk er yha") in which it contained
a sequence of small words (two, three, and four letters words),
(2) research for what are the most frequent words in english of
that size, (3) build all possible permutations using those words,
(4) compare each one of those permutations against some
big text file (like a portion of Wikipedia's backup or the bible),
and then, (5) hopefully seeing what were the most common sentences formed
with of those words, (6) simply manually substitue the letters in
the ciphered text hoping that it would give us a clue about the rest.
Usage: simply run it in the same directory of your file.txt.
"""
FILE = "file.txt" # change to your big text file
SENTENCE_SIZE = 14 # er lonk er yha
ONE_BYTE = 1
ZERO = 0
two_letter_words = ['of', 'to', 'in', 'it', 'is', 'be', 'as', 'at', 'so', 'we']
three_letter_words = ['the', 'and', 'for', 'are', 'but', 'not', 'you', 'all', 'any', 'can']
four_letter_words = ['that', 'with', 'have', 'this', 'will', 'your', 'from', 'they', 'know', 'want']
def build():
sentences_set = set()
for x in two_letter_words:
for y in three_letter_words:
for z in four_letter_words:
sentence = x + ' ' + z + ' ' + x + ' ' + y
sentences_set.add(sentence)
return sentences_set
def evaluate(sentences_set):
sentences_dict = dict()
counter = 1
for sentence in sentences_set:
print('Evaluating sentence ' + str(counter))
result = count_ocurrences(sentence)
sentences_dict[sentence] = result
counter += 1
return sentences_dict
def count_ocurrences(sentence):
ocurrences = ZERO
offset = ZERO
with open(FILE, 'r') as file:
while True:
file.seek(offset)
text = file.read(SENTENCE_SIZE)
if not text:
break
if sentence == text:
ocurrences += 1
offset += ONE_BYTE
return ocurrences
def print_answer():
sentences_set = build()
sentences_dict = evaluate(sentences_set)
for element in sentences_dict.items():
print(element)
if __name__ == "__main__":
print_answer()
@yashgupta1262
Copy link

i decrpt this is an easy question if you want answer then pm telegram @Cirs120

@tanzz1337
Copy link

tanzz1337 commented Sep 28, 2019

Saya mendekripsi ini adalah pertanyaan mudah jika Anda ingin menjawab kemudian pm telegram @ Cirs120

**

can i know the answer or can i contact you via whatsapp or email because i don't have a telegram account ???

**

@yashgupta1262
Copy link

yashgupta1262 commented Sep 28, 2019 via email

@tanzz1337
Copy link

+918750226123 hubungi saya melalui whatsapp
...
On Sat, Sep 28, 2019, 3:16 PM Sultan Raja Marlindo @.***> wrote: Saya mendekripsi ini adalah pertanyaan mudah jika Anda ingin menjawab kemudian pm telegram @ Cirs120 can i know the answer or can i contact you via whatsapp or email because i don't have a telegram account ??? — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://gist.github.com/e51c04a353a6ccad630aa11d88fd1a35?email_source=notifications&email_token=AMSXAW6S3ROFSSZM6VFH3T3QL4RV7A5CNFSM4IBBLQW2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFZRDA#gistcomment-3039792, or mute the thread https://github.com/notifications/unsubscribe-auth/AMSXAWZH23JWBVRSZCWEMQLQL4RV7ANCNFSM4IBBLQWQ .

sorry for before, whatsapp I can not save your number may be a little error may I contact via email

@yashgupta1262
Copy link

yashgupta1262 commented Sep 28, 2019 via email

@sk3lk0
Copy link

sk3lk0 commented Jan 5, 2022

answer is:

substitution ciphers can be broken fairly easily, as long as the cipher text is long enough, and contains enough commonly used characters.

@nuppsknss
Copy link

To solve this problem you need to basically try to guess the letters, run the code and then try to guess the letters once again, but with new information.
Here is the complete dictionary for that problem:
https://pastebin.com/GFYkvaYn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment