repl.it
@xMikee/

FBZ Encoding Tutorial

Python

A step-by-step guide of how "foo-bar-baz" encoding works.

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import re

def fooencode(st):
  print(st)
  st = st[::-1]
  print(st)
  print([x for x in st])
  binary = ' '.join(format(ord(x), 'b') for x in st)
  print(binary)
  binary = binary.replace('00', 'fo')
  print(binary)
  binary = binary.replace('01', 'foo')
  print(binary)
  binary = binary.replace('10', 'br')
  print(binary)
  binary = binary.replace('11', 'bar')
  print(binary)
  binary = binary.replace('0', 'bz')
  print(binary)
  binary = binary.replace('1', 'baz')
  print(binary)
  return binary

def foodecode(binary):
  print(binary)
  binary = re.sub('fo(?!o)', '00', binary)
  print(binary)
  binary = binary.replace('foo', '01')
  print(binary)
  binary = binary.replace('br', '10')
  print(binary)
  binary = binary.replace('bar', '11')
  print(binary)
  binary = binary.replace('bz', '0')
  print(binary)
  binary = binary.replace('baz', '1')
  print(binary)
  print([chr((int(x, 2))) for x in binary.split()])
  decoded = ''.join([chr(int(x, 2)) for x in binary.split()])
  print(decoded)
  return decoded[::-1]

f = fooencode(input('Enter string >> '))
print()
print(foodecode(f))