cryptoCircuitPuzzle.frink

Download or view cryptoCircuitPuzzle.frink in plain text format


// Crypto circuit puzzle by @KoynArtist

// https://twitter.com/KoynArtist/status/856875233931923456
// https://pbs.twimg.com/media/C-Q7eM-W0AAm6rV.jpg

xor3[a,b,c] := a xor b xor c

// Convert a boolean (true or false) to string 1 or 0 respectively.
b2n[b] := b == true ? "1" : "0"

decode[str] :=
{
   bin = padLeft[base2[parseInt[str, 16]], 8, "0"]

   // Convert a 0 or 1 char into false or true respectively
   n2b = {|n|  n == "1" ? true : false }
   [i7, i6, i5, i4, i3, i2, i1, i0] = map[n2b, charList[bin]]

   // Top center left gate
   g1 = xor3[i6, i5, i4]

   // Top center right gate
   g2 = xor3[i2, i1, i0]

   // center gate
   g3 = xor3[g1, i3, g2]

   // leftmost gate
   g4 = i5 xor g3

   // Center left gate
   g6 = g4 xor i4

   // bottom left gate
   g8 = g6 xor i3

   // rightmost gate
   g5 = g8 xor i2

   // Center right gate
   g7 = g5 xor i1

   // Bottom right gate
   g9 = g7 xor i0

   // Output bits
   o7 = i7
   o6 = g3
   o5 = g4
   o4 = g6
   o3 = g8
   o2 = g5
   o1 = g7
   o0 = g9

   binary = b2n[o7] + b2n[o6] + b2n[o5] + b2n[o4] + b2n[o3] + b2n[o2] + b2n[o1] + b2n[o0]

   out = char[parseInt[binary,2]]
   return out
}

input = "6d 30 16 58 30 19 58 0e 30 15 57 51 0b 30 52 58 5b 08 4f 0e 57 0b 4a 39 30 6d 30 15 57 51 0b 30 0e 1c 57 30 1a 51 52 5e 30 58 15 30 0e 1c 57 5b 39 30 7b 6d 4a 4a 51 52 30 61 4a 5d 5b 58 0d"

for [s] = input =~ %r/([0-9a-f]{2})/g
   print[decode[s]]

println[]








Download or view cryptoCircuitPuzzle.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19971 days, 4 hours, 53 minutes ago.