Created
June 14, 2017 21:45
-
-
Save vijayanandrp/6c7919876d936b27b3bda2e19d32ed28 to your computer and use it in GitHub Desktop.
Nullcon HackIM 2014 - Programming 100 Writeup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Well I am a beginner. | |
netcat 23.23.190.204 2002 | |
Welcome | |
Enter 20 spam words to authenticate yourself. | |
01/20: spam | |
02/20: maps | |
03/20: hot | |
Authenticate failed. hot(125) is not a palprime. (Hint) | |
Tried with different test cases and found the value for each alphabet. | |
Since in the challenge only lower-case should be used (condition). | |
so I written a big program ( Once again I am a beginner, | |
to find the palprime words available in dictionary. | |
For the words list I downloaded the dataset from infochimps.com | |
Thank you !!! | |
''' | |
#!/usr/bin/python | |
import string | |
import sys,math | |
import random | |
my_dict ={} | |
a =1 | |
s = 361 | |
t = 762 - s - a | |
n = 196 | |
b = 405 - a -t | |
c = 410 - a - t | |
d =213 - a - n | |
e = 426 - a -t | |
f = 437 -a -t | |
g = 306 - 1 -256 | |
i = 442 - s | |
h = 506 - i - s | |
j = 525 - e -t | |
k = 627 -i -t -e | |
l = 738 -i -g -h -t | |
p = 256 | |
m = 169 | |
o = 274 - g | |
u = 833 - 2*n | |
q = 1211 - u -i -t | |
r = 918 -i -g -h -t | |
v = 885 -a -t | |
w = 651 -i -d -e | |
x = 962 -e -s | |
y = 1587 -e -s -x | |
z = 1030 -e -b -r -a | |
my_dict['a'] = a;my_dict['b'] = b;my_dict['c'] = c;my_dict['d'] = d; | |
my_dict['e'] = e;my_dict['f'] = f;my_dict['g'] = g;my_dict['h'] = h; | |
my_dict['i'] = i;my_dict['j'] = j;my_dict['k'] = k;my_dict['l'] = l; | |
my_dict['m'] = m;my_dict['n'] = n;my_dict['o'] = o;my_dict['p'] =p ; | |
my_dict['q'] = q;my_dict['r'] = r;my_dict['s'] = s;my_dict['t'] = t; | |
my_dict['u'] = u;my_dict['v'] = v;my_dict['w'] = w;my_dict['x'] = x; | |
my_dict['y'] = y;my_dict['z'] =z; | |
def word_generator(size): | |
try: | |
char_set = string.ascii_lowercase # string.ascii_uppercase + string.digits | |
#return ''.join(random.choice(char_set) for x in range(size)) | |
return ''.join(random.sample(char_set*size,size)) | |
except: | |
print 'Error in the generator' | |
sys.exit() | |
def palindrome(sum): | |
try: | |
s = str(sum) | |
if s == s[::-1]: | |
return True | |
else: | |
return False | |
except: | |
print 'Error in the palindrome' | |
sys.exit() | |
def is_prime(n): | |
if n % 2 == 0 and n > 2: | |
return False | |
for i in range(3, int(math.sqrt(n)) + 1, 2): | |
if n % i == 0: | |
return False | |
return True | |
# Anagram Analyzer code | |
dictionary = {} | |
with open("word_list_infochimps.txt", "r") as f: | |
for word in f: | |
word = word.strip().lower() | |
sorted_word = ''.join(sorted(word)) | |
dictionary.setdefault(sorted_word,[]).append(word) | |
final_result =[] | |
f = 0 | |
for check in range(4,8): | |
v = 1000000 | |
while (v > 0): | |
v-=1 | |
rword = str(word_generator(check)) | |
temp = list(rword) | |
sum = 0 | |
for i in temp: | |
sum+= my_dict[i] | |
if palindrome(sum) and is_prime(sum): | |
sorted_rword = ''.join(sorted(rword)) | |
if sorted_rword in dictionary: | |
w = "".join(dictionary[sorted_rword]) | |
if w not in final_result: | |
final_result.append(w) | |
print final_result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment