Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alphabet = ("A".."Z").to_a + ("a".."z").to_a + (0..9).to_a + ["/"] + ["+"]
- str = "test222222222222"
- output = ""
- bits = ""
- str.each_byte do |c|
- bitstr = c.to_s(2).rjust(8, "0")
- bits += bitstr #8 bits long
- end
- bits.scan( /.{1,6}/).each do |x|
- index = x.ljust(6, "0").to_i(2)
- output += alphabet[ index]
- end
- unless output.length % 4 == 0
- pad = (output.length / 4 + 1) * 4
- output.ljust( pad, "=")
- else
- output
- end
Advertisement
Add Comment
Please, Sign In to add comment