Created
July 25, 2012 10:04
-
-
Save Tronix117/3175412 to your computer and use it in GitHub Desktop.
changing character base, need adding some xoring somewhere
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
# Optimised if the BASE array has the same size as a power of 2, otherwise disable symetrie | |
# Optimised if 0 is the first in the BASE array | |
BASE_2 = ['0','1'] | |
BASE_4 = ('0'..'3').to_a | |
BASE_8 = ('0'..'7').to_a | |
BASE_16 = ('0'..'9').to_a + ('a'..'f').to_a | |
BASE_32 = ('0'..'9').to_a + ('a'..'v').to_a | |
BASE_64 = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a + ['$','_'] | |
SHUFFLE_BASE_16 = ['0','4','2','1','8','6','7','5','9','3','c','b','a','f','d','e'] | |
SHUFFLE_BASE_64 = ['0','7','S','q','j','6','N','C','u','8','W','k','4','J','K','5','m','1','F','f','D','X','g','V','n','z','B','i','L','P','l','a','G','s','Q','2','Z','d','v','o','I','x','_','M','Y','c','9','h','$','R','b','U','y','O','A','w','e','p','3','T','E','H','t','r'] | |
def change_charset(str, f, t) | |
def bin_fix_length(b, s) | |
b = '0' + b while b.length < s | |
b | |
end | |
l = (f.length - 1).to_s(2).length | |
str_c = '' | |
while str != '' | |
str_c += bin_fix_length(f.index(str.slice!(0)).to_s(2), l) | |
end | |
str_c.slice!(0) while str_c.slice(0) == '0' | |
l = t.length.to_s(2).length - 1 | |
s = (str_c.length.to_f / l).ceil * l | |
str_c = bin_fix_length(str_c, s) | |
while str_c != '' | |
str = t[str_c.slice!(-l,l).to_i(2)] + str | |
end | |
str | |
end | |
change_charset(Digest::SHA1.hexdigest("1445"), BASE_16, BASE_64) # 64 = 2^6, 16 = 2^4 => compression = 4/6 | |
a = change_charset('17',SHUFFLE_BASE_16, SHUFFLE_BASE_64) # 17 => n | |
change_charset(a, SHUFFLE_BASE_64, SHUFFLE_BASE_16) # n => 17 | |
def gen_salt(s = 2) | |
('a'..'f').to_a.sample(s).join | |
end | |
id=1268727 | |
change_charset(id.to_s + gen_salt, SHUFFLE_BASE_16, SHUFFLE_BASE_64) => 4d1QiW | |
id=1268728 | |
change_charset(id.to_s + gen_salt, SHUFFLE_BASE_16, SHUFFLE_BASE_64) => 4d1QfJ | |
id=1268729 | |
change_charset(id.to_s + gen_salt, SHUFFLE_BASE_16, SHUFFLE_BASE_64) => 4d1QQ3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment