s=[]
s[0]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
s[1]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
s[2]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
s[3]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
s[4]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
s[5]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
s[6]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
s[7]=[
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 2, 14, 10, 0, 6, 13
]
input_text = "trewrewrwerjhkjhjvrtyr4654654vjghg7njljkj80hkjhkvytuytyutytxetret"
ascii=[]
ofset=0;
input_text.each_byte { |f| ascii[input_text.index(f,ofset)]= f ; ofset=ofset+1 } # ASCII
binar= []
ascii.each_index { |index| binar[index] = ascii[index].to_s(2) } # ASCII
binar = binar.to_s #
blocks_of_six = []
j = 0
k = 0
block = ""
# 6
for i in 0 ... binar.length
if j < 6
block = block + binar[i].chr
j = j + 1
else
blocks_of_six[k] = block
block = ""
k = k + 1
j = 0
end
if (i == binar.length-1) && (block != "")
blocks_of_six[k] = block + "0" * (6 - block.length) # 6
end
end
puts blocks_of_six.to_s.length #
sblock = 0
# S -
for i in 0 ... blocks_of_six.length
if sblock == 8
sblock = 0
end
row = ( blocks_of_six[i][0].chr + blocks_of_six[i][5].chr ).to_i(2)
col = blocks_of_six[i][1,4].to_i(2)
blocks_of_six[i] = s[sblock][row * 16 + col]
sblock = sblock + 1
end
binar_after = []
blocks_of_six.each_index { |index| binar_after[index] = blocks_of_six[index].to_s(2) }
for i in 0 ... binar_after.length
if (binar_after[i].length) != 4
binar_after[i] ="0" * (4 - binar_after[i].length) + binar_after[i]
end
end
binar_after = binar_after.to_s
puts binar_after.length #
Source: https://habr.com/ru/post/41662/
All Articles