This commit is contained in:
Roman Hergenreder 2018-12-14 17:11:03 +01:00
parent 9236891cf1
commit 8b34218479
6 changed files with 370303 additions and 18 deletions

110
Day 14/decode.py Normal file

@ -0,0 +1,110 @@
#!/usr/bin/python
import math
c = int("2A4C9AA52257B56837369D5DD7019451C0EC04427EB95EB741D0273D55", 16)
t = int("1398ED7F59A62962D5A47DD0D32B71156DD6AF6B46BEA949976331B8E1", 16)
n = int("0D8A7A45D9BE42BB3F03F710CF105628E8080F6105224612481908DC721", 16)
def linear_diophantine_equation(a, b):
if b > a:
return linear_diophantine_equation(b, a)
if b == 0:
return a, 1, 0
d, x, y = linear_diophantine_equation(b, a % b)
return (d, y, x - (a // b) * y)
def multiplicative_inverse(a, b):
d, x, y = linear_diophantine_equation(a, b)
if y < 0:
y = (b if b > a else a) + y
return y
def gcd(a, b):
d, x, y = linear_diophantine_equation(a, b)
return d
# n > t > c
# m = flag
def test_solution(m):
return m**2 % n == c
# m**2 % n = x**2
# m**2 + k*n = c
# m % n = x
# m - k*n = x
# m = x + k * n
# x = int(math.sqrt(c))
#
# while not test_solution(x):
# x += n
# print(hex(x), hex(((x**2)%n)-c))
# print(x)
mult_inverse = multiplicative_inverse(c, n)
d, x, y = linear_diophantine_equation(mult_inverse, mult_inverse*n)
print(hex(d + 6*t - 2*c), test_solution(d + 6*t - 2*c))
# x = math.sqrt(n)
# print(x)
#
# print(test_solution(c * math.sqrt()))
# print(test_solution(math.floor(math.sqrt(c * n))))
# c = (m**2) % n
# c = m*m - k*n
# 1 = (m**2)/c - (k*n)/c
# 1 = (m**2)/c - k*(n/c)
# k = 1
# test = k * n / c
# while test != math.floor(test):
# k += 1
# test = k * n / c
#
# print(k, test)
# x = m*m
# c = x % n
# c = x - k*n
# c = k*n+x
# x ~ (48 56 31 38 2d) ^ 2
# m_guess = int("485631382d616161612d616161612d616161612d616161612d61616161", 16)
# x_guess = m_guess ** 2
# k_guess = (c - x_guess) / n
#
# i = 0
# while not test_solution(m_guess):
# m_guess += 1
# i += 1
#
# print(i, m_guess)
# print(test_solution(math.sqrt(c + n)))
# print(math.sqrt(c))
# c = x**2
# m**2 % n = x**2
# m % n = x
# i = 0
# solutioni = 0
# while i < 100:
# i += 1
# if test_solution(i):
# print(i, i**2%n)
# 4**2 % 13 = 3
# 9**2 % 13 = 3
# 17**2 % 13 = 3
# 22**2 % 13 = 3
# 30**2 % 13 = 3

9
Day 14/power.ps1 Normal file

@ -0,0 +1,9 @@
. "$PSScriptRoot\flag.ps1" #thumbprint 1398ED7F59A62962D5A47DD0D32B71156DD6AF6B46BEA949976331B8E1
if ($PSVersionTable.PSVersion.Major -gt 2)
{
$m = [System.Numerics.BigInteger]::Parse($flag, 'AllowHexSpecifier');
$n = [System.Numerics.BigInteger]::Parse("0D8A7A45D9BE42BB3F03F710CF105628E8080F6105224612481908DC721", 'AllowHexSpecifier');
$c = [System.Numerics.BigInteger]::ModPow($m, 1+1, $n)
write-host "encrypted flag:" $c.ToString("X");
}

@ -1,5 +1,5 @@
Santa has caught up with the information age and does not trust Santa has caught up with the information age and does not trust
clear-text commands anymore. clear-text commands anymore.
He has decided that all communications He has decided that all communications
have to be encrypted to prevent an unfriendly take-over of his team. have to be encrypted to prevent an unfriendly take-over of his team.
Santa chooses a simple, secure, and toolless encryption scheme. Santa chooses a simple, secure, and toolless encryption scheme.
@ -7,24 +7,8 @@ However, his team's memory capacity is limited and so he can only use
their names (Dasher, Dancer, Prancer, Vixen, Comet, Cupid, Donder and their names (Dasher, Dancer, Prancer, Vixen, Comet, Cupid, Donder and
Blitzen) as keys. Blitzen) as keys.
Dasher
Dancer
Prancer
Vixen
Comet
Cupid
Donder
Blitzen
Where is the team headed to? Where is the team headed to?
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
STTYN YATLOEP DNEA ONBL TGNTO MHEHH EISTIARIB FHSRA LD IIONA NL HERUV LN17-PTAA-RTON-RDOE-MCTN-AHCO STTYN YATLOEP DNEA ONBL TGNTO MHEHH EISTIARIB FHSRA LD IIONA NL HERUV LN17-PTAA-RTON-RDOE-MCTN-AHCO
-4 +8 +0 +1
6 I A B
W I A B
5 H 9 A
-0100 +1000 +0000 +0001

@ -1 +1,84 @@
#!/usr/bin/python #!/usr/bin/python
from itertools import chain, product, permutations
# Santa has caught up with the information age and does not trust
# clear-text commands anymore.
# He has decided that all communications
# have to be encrypted to prevent an unfriendly take-over of his team.
# Santa chooses a simple, secure, and toolless encryption scheme.
# However, his team's memory capacity is limited and so he can only use
# their names (Dasher, Dancer, Prancer, Vixen, Comet, Cupid, Donder and
# Blitzen) as keys.
encrypted = "STTYN YATLOEP DNEA ONBL TGNTO MHEHH EISTIARIB FHSRA LD IIONA NL HERUV LN17-PTAA-RTON-RDOE-MCTN-AHCO"
encrypted_words = encrypted.split(" ")
def load_words():
with open('words_alpha.txt') as word_file:
valid_words = set(word_file.read().split())
return valid_words
english_words = load_words()
# totalCount = 0
# letter_count = {}
# for word in encrypted_words[:-1]:
# totalCount += len(word)
# for letter in word:
# if not letter in letter_count:
# letter_count[letter] = 1
# else:
# letter_count[letter] += 1
# print(letter_count, totalCount)
# def bruteforce(charset, minlength, maxlength):
# return (''.join(candidate)
# for candidate in chain.from_iterable(product(charset, repeat=i)
# for i in range(minlength, maxlength + 1)))
#
# def generateKey(cipher, plain):
# key = ""
# for i in range(min(len(cipher), len(plain))):
# key += chr(ord('A') + ord(cipher[i]) - ord(plain[i]))
# return key
#
def decrypt(cipher, key):
while len(key) < len(cipher):
key += key
return ''.join([chr(ord('A') + (ord(cipher[i]) + ord(key[i]) - 2 * ord('A')) % 26) for i in range(len(cipher))])
possible_keys = ["DASHER","DANCER","PRANCER","VIXEN","COMET","CUPID","DONDER","BLITZEN"]
# startingLetters = [key[0] for key in possible_keys]
# processedKeys = []
#
# for p in permutations(startingLetters, len(startingLetters)):
# key = ''.join(p)
# if key not in processedKeys:
# processedKeys.append(key)
# plain = decrypt(encrypted_words[0], key)
# if plain.lower() in english_words:
# print(key, plain)
for key in possible_keys:
print(key, decrypt(encrypted_words[0], key[::-1]))
#
# for key in bruteforce("ABCDEFGHIJKLMNOPQRSTUVXYZ", 5, 5):
# plain = decrypt(encrypted_words[0], key)
# if key.lower() in english_words and plain.lower() in english_words:
# print(key, plain)
# for word in english_words:
# if len(word) == 5:
# word = word.upper()
# key = generateKey(encrypted_words[0], word).lower()
# # if key.isalpha():
# if key in english_words:
# print(word, key)

File diff suppressed because it is too large Load Diff

BIN
Teaser/footer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 KiB