Last active
July 27, 2019 09:58
-
-
Save tompng/44fce00b7c1736a3c7a0241b08993fdb to your computer and use it in GitHub Desktop.
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
eval(s="tobf=->s{s.chars.map{|c|%([-])+?+*c.ord+?.}.join};a,b=[\"package main;import \\\"fmt\\\";func main(){fmt.Println(\\\"<?php echo(\\\\\\\"print(\\\\\\\\\\\\\\\"console.log(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"#include<stdio.h>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\nint main(){puts(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\", \"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\")\\\\\\\\\\\\\\\")\\\\\\\");\\\")}\"];c=%[eval(s=]+s.inspect+?);5.times{c=c.inspect[1...-1]};puts tobf[a+c+b]") |
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
code = '%s' | |
code = %(#include<stdio.h>\nint main(){puts(#{code.inspect});}) | |
code = %(console.log(#{code.inspect})) | |
code = %(print(#{code.inspect})) | |
code = %(<?php echo(#{code.inspect});) | |
code = %(package main;import "fmt";func main(){fmt.Println(#{code.inspect})}) | |
a,b = code.split('%s') | |
numlangs = 5 | |
c=( | |
'eval(s='+ | |
( | |
%(tobf=->s{s.chars.map{|c|%([-])+?+*c.ord+?.}.join};)+ | |
%(a,b=#{[a,b].inspect};c=%[eval(s=]+s.inspect+?);#{numlangs}.times{c=c.inspect[1...-1]};puts tobf[a+c+b]) | |
).inspect+ | |
')' | |
) | |
numlangs.times{ c=c.inspect[1...-1]} | |
out = a + c + b | |
# puts a | |
# puts b | |
# exit | |
def bfeval code | |
array = [] | |
idx = 0 | |
output = [] | |
eval code.scan(/[\[\].,><+-]/).map(&{ | |
'[' => 'while array[idx].to_i != 0', | |
']' => 'end', | |
'.' => 'output<<array[idx].to_i.chr', | |
',' => 'array[idx] = getc.ord', | |
'+' => 'array[idx] = array[idx].to_i + 1', | |
'-' => 'array[idx] = array[idx].to_i - 1', | |
'>' => 'idx+=1', | |
'<' => 'idx-=1' | |
}).join(';') | |
output.join | |
end | |
puts out | |
File.write('out.go', out) | |
`go run out.go > out.php` | |
`php out.php > out.py` | |
`python out.py > out.js` | |
`node out.js > out.c` | |
`cc out.c && ./a.out > out.rb` | |
`ruby out.rb > out.bf` | |
out2 = bfeval File.read('out.bf') | |
puts out==out2 | |
puts out2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment