Created
February 28, 2015 19:44
-
-
Save ksherlock/50619a2c65260e680601 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'json' | |
kw = %w{ | |
_Bool _Complex _Noreturn _Imaginary | |
auto asm break case char | |
continue const comp default do | |
double else enum extern extended | |
float for goto if int | |
inline long pascal | |
register restrict return | |
short sizeof static struct switch | |
segment signed typedef union unsigned | |
void volatile while | |
} | |
def to_enum(str) | |
case str | |
when "_Bool", "_Complex", "_Noreturn", "_Imaginary" | |
return str.downcase[1,str.length-1] + "sy" | |
else | |
return str + "sy" | |
end | |
end | |
def hash(str) | |
#raise "Target already used: #{target}" if @Used[target] | |
h = 0 | |
str.each_byte{|c| | |
h = h ^ c | |
h = @T[h] | |
} | |
return h | |
end | |
kw.sort! | |
while true do | |
@T = [].fill(0,256) {|x| x }.sample(256) | |
@Used = [].fill(0,256) {|x| false } | |
begin | |
kw.each { |str| | |
h = hash(str) | |
raise str if @Used[h] | |
@Used[h] = str | |
} | |
break | |
rescue Exception => e | |
#puts e | |
next | |
end | |
end | |
@T.each_index{|ix| | |
val = @T[ix] | |
puts " T[#{ix}] := #{val};" | |
} | |
@Used.each_index{|ix| | |
val = @Used[ix] | |
case val | |
when false | |
puts " FinalT[#{ix}] := eofsy;" | |
else | |
puts " FinalT[#{ix}] := #{to_enum(val)};" | |
end | |
} | |
exit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment