aiq / basexx

A Lua library which provides base2(bitfield), base16(hex), base32(crockford/rfc), base64(rfc/url), base85(z85) decoding and encoding.
MIT License
85 stars 28 forks source link

Missing bytes decoding url64 #11

Open singpolyma opened 1 year ago

singpolyma commented 1 year ago

basexx.from_url64("BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4")

this misses the last 3 bytes

aiq commented 1 year ago

Hi,

what values do you expect?

I tested your input string with https://cryptii.com/pipes/base64-to-hex Base64(RFC 4648 §5) and get the following output:

04 25 71 b2 be cd fd e3 60 55 1a af 1e d0 f4 cd 36 6c 11 ce be 55 5f 89 bc b7 b1 86 a5 33 39 17 31 68 ec e2 eb e0 18 59 7b d3 04 79 b8 6e 3c 8f 8e ce d5 77 ca 59 18 7e 92 46 99 0d b6 82 00 8b 0e

Thats the same value that I get in my added test:

`it( "should work with the binary example", function()

  local bin64 = "BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4"
  local bin = string.char( 0x04, 0x25, 0x71, 0xb2, 0xbe, 0xcd, 0xfd, 0xe3, 0x60, 0x55, 0x1a, 0xaf,
                           0x1e, 0xd0, 0xf4, 0xcd, 0x36, 0x6c, 0x11, 0xce, 0xbe, 0x55, 0x5f, 0x89,
                           0xbc, 0xb7, 0xb1, 0x86, 0xa5, 0x33, 0x39, 0x17, 0x31, 0x68, 0xec, 0xe2,
                           0xeb, 0xe0, 0x18, 0x59, 0x7b, 0xd3, 0x04, 0x79, 0xb8, 0x6e, 0x3c, 0x8f,
                           0x8e, 0xce, 0xd5, 0x77, 0xca, 0x59, 0x18, 0x7e, 0x92, 0x46, 0x99, 0x0d,
                           0xb6, 0x82, 0x00, 0x8b, 0x0e )

  assert.is.same( bin64, basexx.to_url64( bin ) )
  assert.is.same( bin, basexx.from_url64( bin64 ) )

end)`

aiq commented 1 year ago

Hi,

what values do you expect?

I tested your input string with https://cryptii.com/pipes/base64-to-hex Base64(RFC 4648 §5) and get the following output:

04 25 71 b2 be cd fd e3 60 55 1a af 1e d0 f4 cd 36 6c 11 ce be 55 5f 89 bc b7 b1 86 a5 33 39 17 31 68 ec e2 eb e0 18 59 7b d3 04 79 b8 6e 3c 8f 8e ce d5 77 ca 59 18 7e 92 46 99 0d b6 82 00 8b 0e

Thats the same value that I get in my added test:

it( "should work with the binary example", function()

   local bin64 = "BCVxsr7N_eNgVRqvHtD0zTZsEc6-VV-JvLexhqUzORcxaOzi6-AYWXvTBHm4bjyPjs7Vd8pZGH6SRpkNtoIAiw4"
   local bin = string.char( 0x04, 0x25, 0x71, 0xb2, 0xbe, 0xcd, 0xfd, 0xe3, 0x60, 0x55, 0x1a, 0xaf,
                            0x1e, 0xd0, 0xf4, 0xcd, 0x36, 0x6c, 0x11, 0xce, 0xbe, 0x55, 0x5f, 0x89,
                            0xbc, 0xb7, 0xb1, 0x86, 0xa5, 0x33, 0x39, 0x17, 0x31, 0x68, 0xec, 0xe2,
                            0xeb, 0xe0, 0x18, 0x59, 0x7b, 0xd3, 0x04, 0x79, 0xb8, 0x6e, 0x3c, 0x8f,
                            0x8e, 0xce, 0xd5, 0x77, 0xca, 0x59, 0x18, 0x7e, 0x92, 0x46, 0x99, 0x0d,
                            0xb6, 0x82, 0x00, 0x8b, 0x0e )

   assert.is.same( bin64, basexx.to_url64( bin ) )
   assert.is.same( bin, basexx.from_url64( bin64 ) )
end)