Skip to content

Instantly share code, notes, and snippets.

@LevitatingBusinessMan
Created January 13, 2020 23:28
Show Gist options
  • Select an option

  • Save LevitatingBusinessMan/43e0e46b009e0112a8295117aa02a233 to your computer and use it in GitHub Desktop.

Select an option

Save LevitatingBusinessMan/43e0e46b009e0112a8295117aa02a233 to your computer and use it in GitHub Desktop.
Google CTF 2019 Emoji challenge
# calculate reversible primes
primes = []
num = 1
def calcPrimes(start):
global num
while len(primes) - start < len(stack):
if all(num % i != 0 for i in range(2,num)):
if "".join(reversed(str(num))) == str(num):
primes.append(num)
num += 1
def decipher(start):
for i in range(0, len(stack)):
print(chr(int(stack[i]) ^ primes[i + start]), end="")
# First group
stack = [
'17488', '16758', '16599', '16285',
'16094', '15505', '15417', '14832', '14450',
'13893', '13926', '13437', '12833', '12741',
'12533', '11504', '11342', '10503', '10550',
'10319', '975', '1007', '892', '893',
'660', '743', '267', '344', '264',
'339', '208', '216', '242', '172',
'74', '49', '119', '113', '119',
'106'
]
stack.reverse()
calcPrimes(1)
decipher(1)
# Second group
stack = [
'98426', '97850',
'97604', '97280',
'96815', '96443',
'96354', '95934',
'94865', '94952',
'94669', '94440',
'93969', '93766'
]
stack.reverse()
calcPrimes(99)
decipher(99)
# Third group
stack = [
'101141058', '101060206', '101030055',
'100998966', '100887990', '100767085',
'100707036', '100656111', '100404094',
'100160922', '100131019', '100111100',
'100059926', '100049982', '100030045',
'9989997', '9981858', '9980815',
'9978842', '9965794', '9957564',
'9938304', '9935427', '9932289',
'9931494', '9927388', '9926376',
'9923213', '9921394', '9919154',
'9918082', '9916239'
]
stack.reverse()
calcPrimes(765)
decipher(765)
print()
some algorithm goes over elements in the stack
the output of this is used with a set XOR key and the output is a unicode character in decimal.
The stack is split into 3 where the acc2 variable is different during the deciphering
2 ^ 106 = h
3 ^ 119 = t
5 ^ 113 = t
7 ^ 119 = p
11 ^ 49 = :
101 ^ 74 = /
131 ^ 172 = /
151 ^ 242 = e
181 ^ 216 = m
191 ^ 208 = o
313 ^ 339 = j
353 ^ 264 = i
first number is every prime number which is the same when reversed
for some reason the second batch never runs, though the only different factors seem to be the stack itself, the acc1 and the acc2
when any of these are changed code the url does not display
after having to google (sorry) for solutions I found that the acc2 value is the prime to start from...
πŸš› πŸ₯‡ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 7️⃣ 4️⃣ 8️⃣ 8️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 6️⃣ 7️⃣ 5️⃣ 8️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 6️⃣ 5️⃣ 9️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 6️⃣ 2️⃣ 8️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 6️⃣ 0️⃣ 9️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 5️⃣ 5️⃣ 0️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 5️⃣ 4️⃣ 1️⃣ 7️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 4️⃣ 8️⃣ 3️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 4️⃣ 4️⃣ 5️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 3️⃣ 8️⃣ 9️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 3️⃣ 9️⃣ 2️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 3️⃣ 4️⃣ 3️⃣ 7️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 2️⃣ 8️⃣ 3️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 2️⃣ 7️⃣ 4️⃣ 1️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 2️⃣ 5️⃣ 3️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 1️⃣ 5️⃣ 0️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 1️⃣ 3️⃣ 4️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 5️⃣ 0️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 5️⃣ 5️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 3️⃣ 1️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 7️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 7️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 8️⃣ 9️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 8️⃣ 9️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 6️⃣ 6️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 7️⃣ 4️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 2️⃣ 6️⃣ 7️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 3️⃣ 4️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 2️⃣ 6️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 3️⃣ 3️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 2️⃣ 0️⃣ 8️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 2️⃣ 1️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 2️⃣ 4️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 7️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 7️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 4️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 1️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 1️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 1️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯ˆ 1️⃣ βœ‹
πŸ–‹πŸ’ πŸ”ΆπŸŽŒπŸš©πŸ 🍿 πŸ₯‡ πŸ“₯ πŸ₯ˆ πŸ“₯ πŸ₯‡ πŸš› πŸ₯‡ 3️⃣ 8️⃣ 9️⃣ βœ‹
πŸ“₯ πŸ₯‡ πŸ“₯ πŸ₯ˆ
πŸ€ πŸ’°πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
πŸŒ“ 🎀
πŸš› πŸ₯‡ 1️⃣ βœ‹ πŸ“₯ πŸ₯‡ 🍑 🍿 πŸ₯ˆ
πŸ˜„ πŸ€ πŸ’°πŸ’ πŸ”ΆπŸŽŒπŸš©πŸ 😐
πŸš› πŸ₯‡ 9️⃣ 8️⃣ 4️⃣ 2️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 7️⃣ 8️⃣ 5️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 7️⃣ 6️⃣ 0️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 7️⃣ 2️⃣ 8️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 6️⃣ 8️⃣ 1️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 6️⃣ 4️⃣ 4️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 6️⃣ 3️⃣ 5️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 5️⃣ 9️⃣ 3️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 4️⃣ 8️⃣ 6️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 4️⃣ 9️⃣ 5️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 4️⃣ 6️⃣ 6️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 4️⃣ 4️⃣ 4️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 3️⃣ 9️⃣ 6️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 3️⃣ 7️⃣ 6️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯ˆ 9️⃣ 9️⃣ βœ‹
πŸ–‹πŸ’ πŸπŸŽŒπŸ”ΆπŸš© 🍿 πŸ₯‡ πŸ“₯ πŸ₯ˆ πŸ“₯ πŸ₯‡ πŸš› πŸ₯‡ 5️⃣ 6️⃣ 8️⃣ βœ‹
πŸ“₯ πŸ₯‡ πŸ“₯ πŸ₯ˆ
πŸ€ πŸ’°πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
πŸŒ“ 🎀
πŸš› πŸ₯‡ 1️⃣ βœ‹ πŸ“₯ πŸ₯‡ 🍑 🍿 πŸ₯ˆ
πŸ˜„ πŸ€ πŸ’°πŸ’ πŸπŸŽŒπŸ”ΆπŸš© 😐
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 1️⃣ 1️⃣ 4️⃣ 1️⃣ 0️⃣ 5️⃣ 8️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 1️⃣ 0️⃣ 6️⃣ 0️⃣ 2️⃣ 0️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 1️⃣ 0️⃣ 3️⃣ 0️⃣ 0️⃣ 5️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 9️⃣ 9️⃣ 8️⃣ 9️⃣ 6️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 8️⃣ 8️⃣ 7️⃣ 9️⃣ 9️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 7️⃣ 6️⃣ 7️⃣ 0️⃣ 8️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 7️⃣ 0️⃣ 7️⃣ 0️⃣ 3️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 6️⃣ 5️⃣ 6️⃣ 1️⃣ 1️⃣ 1️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 4️⃣ 0️⃣ 4️⃣ 0️⃣ 9️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 1️⃣ 6️⃣ 0️⃣ 9️⃣ 2️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 1️⃣ 3️⃣ 1️⃣ 0️⃣ 1️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 1️⃣ 1️⃣ 1️⃣ 1️⃣ 0️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 0️⃣ 5️⃣ 9️⃣ 9️⃣ 2️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 0️⃣ 4️⃣ 9️⃣ 9️⃣ 8️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 1️⃣ 0️⃣ 0️⃣ 0️⃣ 3️⃣ 0️⃣ 0️⃣ 4️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 8️⃣ 9️⃣ 9️⃣ 9️⃣ 7️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 8️⃣ 1️⃣ 8️⃣ 5️⃣ 8️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 8️⃣ 0️⃣ 8️⃣ 1️⃣ 5️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 7️⃣ 8️⃣ 8️⃣ 4️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 6️⃣ 5️⃣ 7️⃣ 9️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 5️⃣ 7️⃣ 5️⃣ 6️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 3️⃣ 8️⃣ 3️⃣ 0️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 3️⃣ 5️⃣ 4️⃣ 2️⃣ 7️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 3️⃣ 2️⃣ 2️⃣ 8️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 3️⃣ 1️⃣ 4️⃣ 9️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 2️⃣ 7️⃣ 3️⃣ 8️⃣ 8️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 2️⃣ 6️⃣ 3️⃣ 7️⃣ 6️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 2️⃣ 3️⃣ 2️⃣ 1️⃣ 3️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 2️⃣ 1️⃣ 3️⃣ 9️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 1️⃣ 9️⃣ 1️⃣ 5️⃣ 4️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 1️⃣ 8️⃣ 0️⃣ 8️⃣ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯‡ 9️⃣ 9️⃣ 1️⃣ 6️⃣ 2️⃣ 3️⃣ 9️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸš› πŸ₯ˆ 7️⃣ 6️⃣ 5️⃣ βœ‹
πŸ–‹πŸš©πŸ’ πŸŽŒπŸ”ΆπŸ 🍿 πŸ₯‡ πŸ“₯ πŸ₯ˆ πŸ“₯ πŸ₯‡ πŸš› πŸ₯‡ 1️⃣ 0️⃣ 2️⃣ 3️⃣ βœ‹
πŸ“₯ πŸ₯‡ πŸ“₯ πŸ₯ˆ
πŸ€ πŸ’°πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
πŸŒ“ 🎀
πŸš› πŸ₯‡ 1️⃣ βœ‹ πŸ“₯ πŸ₯‡ 🍑 🍿 πŸ₯ˆ
πŸ˜„ πŸ€ πŸ’°πŸš©πŸ’ πŸŽŒπŸ”ΆπŸ 😐
βŒ›
πŸ–‹πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
πŸš› πŸ₯‡ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡ πŸ–‹πŸ’ πŸŽŒπŸπŸš©πŸ”Ά
πŸ€ πŸ’°πŸš©πŸ”ΆπŸπŸŽŒπŸ’ 
πŸ–‹πŸ”ΆπŸŽŒπŸš©πŸ’ πŸ 😲 πŸ“€ πŸ€ πŸ’°πŸ”ΆπŸš©πŸ’ πŸπŸŽŒ βœ‹ 😐
πŸ“€ πŸ€ πŸ’°πŸŽŒπŸπŸ’ πŸ”ΆπŸš©
πŸ–‹πŸŽŒπŸπŸš©πŸ”ΆπŸ’  😲 πŸ“€ πŸ€ πŸ’°πŸ”ΆπŸš©πŸ’ πŸπŸŽŒ 😐
πŸ“€ 🍿 πŸ₯‡ πŸš› πŸ₯ˆ 1️⃣ βœ‹ πŸ“₯ πŸ₯ˆ πŸ”ͺ
😲 πŸ“€ 🍿 πŸ₯ˆ πŸ“₯ πŸ₯‡ πŸ“₯ πŸ₯ˆ β›° 😐 πŸ“₯ πŸ₯‡
πŸ–‹πŸ”ΆπŸš©πŸ’ πŸπŸŽŒ πŸš› πŸ₯ˆ 1️⃣ βœ‹ πŸ“₯ πŸ₯ˆ 🍑 πŸ€ πŸ’°πŸ’ πŸŽŒπŸπŸš©πŸ”Ά
πŸ–‹πŸš©πŸ”ΆπŸπŸŽŒπŸ’ 
🀑 πŸš› πŸ₯‡ 2️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸ–‹πŸŽŒπŸš©πŸ’ πŸ”ΆπŸ πŸ”ͺ 😲 πŸ“€ πŸš› πŸ₯‡ 1️⃣ βœ‹ πŸ“₯ πŸ₯‡
πŸ€ πŸ’°πŸ”ΆπŸŽŒπŸš©πŸ’ πŸ 😐
πŸ“€ 🀑 πŸ“₯ πŸ₯‡
πŸ“¬ 😲 πŸ€ πŸ’°πŸ”ΆπŸŽŒπŸš©πŸ’ πŸ 😐
πŸ“€ 🀑 πŸ“₯ πŸ₯‡ πŸš› πŸ₯‡ 1️⃣ βœ‹
πŸ“₯ πŸ₯‡ 🍑 🀑 🍿 πŸ₯‡ πŸ€ πŸ’°πŸŽŒπŸš©πŸ’ πŸ”ΆπŸ
πŸ–‹πŸŽŒπŸπŸ’ πŸ”ΆπŸš©
🀑 🀑 πŸš› πŸ₯ˆ 0️⃣ βœ‹ πŸ“₯ πŸ₯ˆ
πŸ–‹πŸπŸ’ πŸ”ΆπŸš©πŸŽŒ πŸš› πŸ₯‡ 1️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡
⭐ 🍿 πŸ₯ˆ πŸ“₯ πŸ₯‡ πŸ“¬
πŸ“₯ πŸ₯ˆ 🍑 🍿 πŸ₯ˆ 🍿 πŸ₯‡ 🀑 πŸ“₯ πŸ₯ˆ πŸ”ͺ
😲 πŸ“€ πŸš› πŸ₯ˆ 1️⃣ βœ‹ πŸ“₯ πŸ₯ˆ πŸ€ πŸ’°πŸŽŒπŸπŸš©πŸ”ΆπŸ’  😐
πŸ“€ πŸ“₯ πŸ₯‡ πŸš› πŸ₯‡ 1️⃣ 0️⃣ βœ‹ πŸ“₯ πŸ₯‡ πŸ“
😲 πŸ€ πŸ’°πŸŽŒπŸπŸš©πŸ”ΆπŸ’  😐
🀑 πŸ“₯ πŸ₯ˆ πŸ€ πŸ’°πŸπŸ’ πŸ”ΆπŸš©πŸŽŒ
load acc1 0️ endl push acc1
load acc1 1️ 7️ 4️ 8️ 8️ endl push acc1
load acc1 1️ 6️ 7️ 5️ 8️ endl push acc1
load acc1 1️ 6️ 5️ 9️ 9️ endl push acc1
load acc1 1️ 6️ 2️ 8️ 5️ endl push acc1
load acc1 1️ 6️ 0️ 9️ 4️ endl push acc1
load acc1 1️ 5️ 5️ 0️ 5️ endl push acc1
load acc1 1️ 5️ 4️ 1️ 7️ endl push acc1
load acc1 1️ 4️ 8️ 3️ 2️ endl push acc1
load acc1 1️ 4️ 4️ 5️ 0️ endl push acc1
load acc1 1️ 3️ 8️ 9️ 3️ endl push acc1
load acc1 1️ 3️ 9️ 2️ 6️ endl push acc1
load acc1 1️ 3️ 4️ 3️ 7️ endl push acc1
load acc1 1️ 2️ 8️ 3️ 3️ endl push acc1
load acc1 1️ 2️ 7️ 4️ 1️ endl push acc1
load acc1 1️ 2️ 5️ 3️ 3️ endl push acc1
load acc1 1️ 1️ 5️ 0️ 4️ endl push acc1
load acc1 1️ 1️ 3️ 4️ 2️ endl push acc1
load acc1 1️ 0️ 5️ 0️ 3️ endl push acc1
load acc1 1️ 0️ 5️ 5️ 0️ endl push acc1
load acc1 1️ 0️ 3️ 1️ 9️ endl push acc1
load acc1 9️ 7️ 5️ endl push acc1
load acc1 1️ 0️ 0️ 7️ endl push acc1
load acc1 8️ 9️ 2️ endl push acc1
load acc1 8️ 9️ 3️ endl push acc1
load acc1 6️ 6️ 0️ endl push acc1
load acc1 7️ 4️ 3️ endl push acc1
load acc1 2️ 6️ 7️ endl push acc1
load acc1 3️ 4️ 4️ endl push acc1
load acc1 2️ 6️ 4️ endl push acc1
load acc1 3️ 3️ 9️ endl push acc1
load acc1 2️ 0️ 8️ endl push acc1
load acc1 2️ 1️ 6️ endl push acc1
load acc1 2️ 4️ 2️ endl push acc1
load acc1 1️ 7️ 2️ endl push acc1
load acc1 7️ 4️ endl push acc1
load acc1 4️ 9️ endl push acc1
load acc1 1️ 1️ 9️ endl push acc1
load acc1 1️ 1️ 3️ endl push acc1
load acc1 1️ 1️ 9️ endl push acc1
load acc1 1️ 0️ 6️ endl push acc1
load acc2 1️ endl
>πŸ’ πŸ”ΆπŸŽŒπŸš©πŸ pop acc1 push acc2 push acc1 load acc1 3️ 8️ 9️ endl
push acc1 push acc2
jump_to >πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
xor print_top
load acc1 1️ endl push acc1 add pop acc2
if_not_zero jump_to >πŸ’ πŸ”ΆπŸŽŒπŸš©πŸ fi
load acc1 9️ 8️ 4️ 2️ 6️ endl push acc1
load acc1 9️ 7️ 8️ 5️ 0️ endl push acc1
load acc1 9️ 7️ 6️ 0️ 4️ endl push acc1
load acc1 9️ 7️ 2️ 8️ 0️ endl push acc1
load acc1 9️ 6️ 8️ 1️ 5️ endl push acc1
load acc1 9️ 6️ 4️ 4️ 3️ endl push acc1
load acc1 9️ 6️ 3️ 5️ 4️ endl push acc1
load acc1 9️ 5️ 9️ 3️ 4️ endl push acc1
load acc1 9️ 4️ 8️ 6️ 5️ endl push acc1
load acc1 9️ 4️ 9️ 5️ 2️ endl push acc1
load acc1 9️ 4️ 6️ 6️ 9️ endl push acc1
load acc1 9️ 4️ 4️ 4️ 0️ endl push acc1
load acc1 9️ 3️ 9️ 6️ 9️ endl push acc1
load acc1 9️ 3️ 7️ 6️ 6️ endl push acc1
load acc2 9️ 9️ endl
>πŸ’ πŸπŸŽŒπŸ”ΆπŸš© pop acc1 push acc2 push acc1 load acc1 5️ 6️ 8️ endl
push acc1 push acc2
jump_to >πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
xor print_top
load acc1 1️ endl push acc1 add pop acc2
if_not_zero jump_to >πŸ’ πŸπŸŽŒπŸ”ΆπŸš© fi
load acc1 1️ 0️ 1️ 1️ 4️ 1️ 0️ 5️ 8️ endl push acc1
load acc1 1️ 0️ 1️ 0️ 6️ 0️ 2️ 0️ 6️ endl push acc1
load acc1 1️ 0️ 1️ 0️ 3️ 0️ 0️ 5️ 5️ endl push acc1
load acc1 1️ 0️ 0️ 9️ 9️ 8️ 9️ 6️ 6️ endl push acc1
load acc1 1️ 0️ 0️ 8️ 8️ 7️ 9️ 9️ 0️ endl push acc1
load acc1 1️ 0️ 0️ 7️ 6️ 7️ 0️ 8️ 5️ endl push acc1
load acc1 1️ 0️ 0️ 7️ 0️ 7️ 0️ 3️ 6️ endl push acc1
load acc1 1️ 0️ 0️ 6️ 5️ 6️ 1️ 1️ 1️ endl push acc1
load acc1 1️ 0️ 0️ 4️ 0️ 4️ 0️ 9️ 4️ endl push acc1
load acc1 1️ 0️ 0️ 1️ 6️ 0️ 9️ 2️ 2️ endl push acc1
load acc1 1️ 0️ 0️ 1️ 3️ 1️ 0️ 1️ 9️ endl push acc1
load acc1 1️ 0️ 0️ 1️ 1️ 1️ 1️ 0️ 0️ endl push acc1
load acc1 1️ 0️ 0️ 0️ 5️ 9️ 9️ 2️ 6️ endl push acc1
load acc1 1️ 0️ 0️ 0️ 4️ 9️ 9️ 8️ 2️ endl push acc1
load acc1 1️ 0️ 0️ 0️ 3️ 0️ 0️ 4️ 5️ endl push acc1
load acc1 9️ 9️ 8️ 9️ 9️ 9️ 7️ endl push acc1
load acc1 9️ 9️ 8️ 1️ 8️ 5️ 8️ endl push acc1
load acc1 9️ 9️ 8️ 0️ 8️ 1️ 5️ endl push acc1
load acc1 9️ 9️ 7️ 8️ 8️ 4️ 2️ endl push acc1
load acc1 9️ 9️ 6️ 5️ 7️ 9️ 4️ endl push acc1
load acc1 9️ 9️ 5️ 7️ 5️ 6️ 4️ endl push acc1
load acc1 9️ 9️ 3️ 8️ 3️ 0️ 4️ endl push acc1
load acc1 9️ 9️ 3️ 5️ 4️ 2️ 7️ endl push acc1
load acc1 9️ 9️ 3️ 2️ 2️ 8️ 9️ endl push acc1
load acc1 9️ 9️ 3️ 1️ 4️ 9️ 4️ endl push acc1
load acc1 9️ 9️ 2️ 7️ 3️ 8️ 8️ endl push acc1
load acc1 9️ 9️ 2️ 6️ 3️ 7️ 6️ endl push acc1
load acc1 9️ 9️ 2️ 3️ 2️ 1️ 3️ endl push acc1
load acc1 9️ 9️ 2️ 1️ 3️ 9️ 4️ endl push acc1
load acc1 9️ 9️ 1️ 9️ 1️ 5️ 4️ endl push acc1
load acc1 9️ 9️ 1️ 8️ 0️ 8️ 2️ endl push acc1
load acc1 9️ 9️ 1️ 6️ 2️ 3️ 9️ endl push acc1
load acc2 7️ 6️ 5️ endl
>πŸš©πŸ’ πŸŽŒπŸ”ΆπŸ pop acc1 push acc2 push acc1 load acc1 1️ 0️ 2️ 3️ endl
push acc1 push acc2
jump_to >πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
xor print_top
load acc1 1️ endl push acc1 add pop acc2
if_not_zero jump_to >πŸš©πŸ’ πŸŽŒπŸ”ΆπŸ fi
exit
>πŸπŸš©πŸŽŒπŸ’ πŸ”Ά
load acc1 2️ endl push acc1 >πŸ’ πŸŽŒπŸπŸš©πŸ”Ά
jump_to >πŸš©πŸ”ΆπŸπŸŽŒπŸ’ 
>πŸ”ΆπŸŽŒπŸš©πŸ’ πŸ if_zero pop_out jump_to >πŸ”ΆπŸš©πŸ’ πŸπŸŽŒ endl fi
pop_out jump_to >πŸŽŒπŸπŸ’ πŸ”ΆπŸš©
>πŸŽŒπŸπŸš©πŸ”ΆπŸ’  if_zero pop_out jump_to >πŸ”ΆπŸš©πŸ’ πŸπŸŽŒ fi
pop_out pop acc1 load acc2 1️ endl push acc2 sub
if_zero pop_out pop acc2 push acc1 push acc2 jump_top fi push acc1
>πŸ”ΆπŸš©πŸ’ πŸπŸŽŒ load acc2 1️ endl push acc2 add jump_to >πŸ’ πŸŽŒπŸπŸš©πŸ”Ά
>πŸš©πŸ”ΆπŸπŸŽŒπŸ’ 
clone load acc1 2️ endl push acc1
>πŸŽŒπŸš©πŸ’ πŸ”ΆπŸ sub if_zero pop_out load acc1 1️ endl push acc1
jump_to >πŸ”ΆπŸŽŒπŸš©πŸ’ πŸ fi
pop_out clone push acc1
modulo if_zero jump_to >πŸ”ΆπŸŽŒπŸš©πŸ’ πŸ fi
pop_out clone push acc1 load acc1 1️ endl
push acc1 add clone pop acc1 jump_to >πŸŽŒπŸš©πŸ’ πŸ”ΆπŸ
>πŸŽŒπŸπŸ’ πŸ”ΆπŸš©
clone clone load acc2 0️ endl push acc2
>πŸπŸ’ πŸ”ΆπŸš©πŸŽŒ load acc1 1️ 0️ endl push acc1
multiply pop acc2 push acc1 modulo
push acc2 add pop acc2 pop acc1 clone push acc2 sub
if_zero pop_out load acc2 1️ endl push acc2 jump_to >πŸŽŒπŸπŸš©πŸ”ΆπŸ’  fi
pop_out push acc1 load acc1 1️ 0️ endl push acc1 divide
if_zero jump_to >πŸŽŒπŸπŸš©πŸ”ΆπŸ’  fi
clone push acc2 jump_to >πŸπŸ’ πŸ”ΆπŸš©πŸŽŒ
import re
with open("program", "r") as f:
all_ins = [""]
all_ins.extend(re.split("",f.read()))
translations = {
"🍑": "add",
"🀑": "clone",
"πŸ“": "divide",
"😲": "if_zero",
"πŸ˜„": "if_not_zero",
"πŸ€": "jump_to",
"πŸš›": "load",
"πŸ“¬": "modulo",
"⭐": "multiply",
"🍿": "pop",
"πŸ“€": "pop_out",
"🎀": "print_top",
"πŸ“₯": "push",
"πŸ”ͺ": "sub",
"πŸŒ“": "xor",
"β›°": "jump_top",
"βŒ›": "exit",
"😐": "fi",
"πŸ₯‡": "acc1",
"πŸ₯ˆ": "acc2",
"βœ‹": "endl",
"πŸ–‹": ">",
"πŸ’°": ">"
}
for i in range(0, len(all_ins)):
ins = all_ins[i]
if ins in translations:
all_ins[i] = translations[ins]
out = open("program.trans","w")
# parse text without box symbols for the numbers
translation = "".join(all_ins).replace(chr(8419), "")
out.write(translation)
import sys
# Implements a simple stack-based VM
class VM:
def __init__(self, rom):
self.rom = rom
self.accumulator1 = 0
self.accumulator2 = 0
self.instruction_pointer = 1
self.stack = []
def step(self):
cur_ins = self.rom[self.instruction_pointer]
self.instruction_pointer += 1
fn = VM.OPERATIONS.get(cur_ins, None)
if cur_ins[0] == 'πŸ–‹':
return
if fn is None:
raise RuntimeError("Unknown instruction '{}' at {}".format(
repr(cur_ins), self.instruction_pointer - 1))
else:
fn(self)
def add(self):
self.stack.append(self.stack.pop() + self.stack.pop())
def sub(self):
a = self.stack.pop()
b = self.stack.pop()
self.stack.append(b - a)
def if_zero(self):
if self.stack[-1] == 0:
while self.rom[self.instruction_pointer] != '😐':
if self.rom[self.instruction_pointer] in ['πŸ€', 'β›°']:
break
self.step()
else:
self.find_first_endif()
self.instruction_pointer += 1
def if_not_zero(self):
if self.stack[-1] != 0:
while self.rom[self.instruction_pointer] != '😐':
if self.rom[self.instruction_pointer] in ['πŸ€', 'β›°']:
break
self.step()
else:
self.find_first_endif()
self.instruction_pointer += 1
def find_first_endif(self):
while self.rom[self.instruction_pointer] != '😐':
self.instruction_pointer += 1
def jump_to(self):
marker = self.rom[self.instruction_pointer]
if marker[0] != 'πŸ’°':
print('Incorrect symbol : ' + marker[0])
raise SystemExit()
marker = 'πŸ–‹' + marker[1:]
self.instruction_pointer = self.rom.index(marker) + 1
def jump_top(self):
self.instruction_pointer = self.stack.pop()
def exit(self):
print('\nDone.')
raise SystemExit()
def print_top(self):
sys.stdout.write(chr(self.stack.pop()))
sys.stdout.flush()
def push(self):
if self.rom[self.instruction_pointer] == 'πŸ₯‡':
self.stack.append(self.accumulator1)
elif self.rom[self.instruction_pointer] == 'πŸ₯ˆ':
self.stack.append(self.accumulator2)
else:
raise RuntimeError('Unknown instruction {} at position {}'.format(
self.rom[self.instruction_pointer], str(self.instruction_pointer)))
self.instruction_pointer += 1
def pop(self):
if self.rom[self.instruction_pointer] == 'πŸ₯‡':
self.accumulator1 = self.stack.pop()
elif self.rom[self.instruction_pointer] == 'πŸ₯ˆ':
self.accumulator2 = self.stack.pop()
else:
raise RuntimeError('Unknown instruction {} at position {}'.format(
self.rom[self.instruction_pointer], str(self.instruction_pointer)))
self.instruction_pointer += 1
def pop_out(self):
self.stack.pop()
def load(self):
num = 0
if self.rom[self.instruction_pointer] == 'πŸ₯‡':
acc = 1
elif self.rom[self.instruction_pointer] == 'πŸ₯ˆ':
acc = 2
else:
raise RuntimeError('Unknown instruction {} at position {}'.format(
self.rom[self.instruction_pointer], str(self.instruction_pointer)))
self.instruction_pointer += 1
while self.rom[self.instruction_pointer] != 'βœ‹':
num = num * 10 + (ord(self.rom[self.instruction_pointer][0]) - ord('0'))
self.instruction_pointer += 1
if acc == 1:
self.accumulator1 = num
else:
self.accumulator2 = num
self.instruction_pointer += 1
def clone(self):
self.stack.append(self.stack[-1])
def multiply(self):
a = self.stack.pop()
b = self.stack.pop()
self.stack.append(b * a)
def divide(self):
a = self.stack.pop()
b = self.stack.pop()
self.stack.append(b // a)
def modulo(self):
a = self.stack.pop()
b = self.stack.pop()
self.stack.append(b % a)
def xor(self):
a = self.stack.pop()
b = self.stack.pop()
self.stack.append(b ^ a)
OPERATIONS = {
'🍑': add,
'🀑': clone,
'πŸ“': divide,
'😲': if_zero,
'πŸ˜„': if_not_zero,
'πŸ€': jump_to,
'πŸš›': load,
'πŸ“¬': modulo,
'⭐': multiply,
'🍿': pop,
'πŸ“€': pop_out,
'🎀': print_top,
'πŸ“₯': push,
'πŸ”ͺ': sub,
'πŸŒ“': xor,
'β›°': jump_top,
'βŒ›': exit
}
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Missing program')
raise SystemExit()
with open(sys.argv[1], 'r') as f:
print('Running ....')
all_ins = ['']
all_ins.extend(f.read().split())
vm = VM(all_ins)
while 1:
vm.step()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment