Jump to content
Tuts 4 You

Cpp Miracl base problem


ragdog

Recommended Posts

Hey Comuntity


 


I try my luck in Cpp now have i a problem with Miracl


 



miracl *mip=mirsys(256, 0);
mip->IOBASE=16; big t=mirvar(0);
cinstr(t, "666AAA422FDF79E1D4E41EDDC4D42C51"); mip->IOBASE=64;
cotstr(t, buff);
// ZmqqQi/feeHU5B7dxNQsUQ
mirkill(t);

 


I try to convert a base 16 string "666AAA422FDF79E1D4E41EDDC4D42C51"


to base 64 "ZmqqQi/feeHU5B7dxNQsUQ"


 


Have any an idea why i have the wrong result?


 


Regards,


Link to comment

Base64 string "ZmqqQi/feeHU5B7dxNQsUQ" decodes to byte sequence "66 6A AA 42 2F DF 79 E1 D4 E4 1E DD C4 D4 2C 51", so it looks correct. 


 


What is the expected result?


Link to comment

Hi


 


Thanks for your answhere


 


I have a Hex sequence "666AAA422FDF79E1D4E41EDDC4D42C51" it is base 16 now i would like


convert to base 64 "ZmqqQi/feeHU5B7dxNQsUQ" with the Miracl


 


Try Rsa Tool  it give me a result "ZmqqQi/feeHU5B7dxNQsUQ"


Edited by ragdog
Link to comment

:scratch:  Is this Base 64 no


 


It use only  IOBASE 16


And i need help to convert a  IOBASE 16 string to output IOBASE 64


Edited by ragdog
Link to comment
Important: Base64 number format is not supported by MIRACL. I used own

routines. Conversion goes from MSB to LSB of the hex representation of

each number. This may be incompatible with conversion routines of your

favourite lib.Sourcecode in C for the base64 conversion comes bundled with

this Tool.

Link to comment

Hi

 

Is this from a older Miracl Sdk?

 

In the last Sdk can i read

 

Version 4.7.4
Base64 I/O supported. Just set IOBASE=64 before input/output

 

I have test with older Miracl sdk (*.lib)

 

And I have different results with the same code in my project

Has the last sdk an error by base 64?

 

String to convert = 2E4E30DAB
Output                =  Lk4w2r      older miracl

Output                =  AALk4w2r  last miracl

 

 

Regards,

Edited by ragdog
Link to comment

Is it 02E4E30DAB or 2E4E30DAB0 ?


You didn't gave a pair number of characters, meaning you omitted a char or a zero. In this case, the first output took away the last char because it was alone so not a byte (2E4E30DA) and in the second case it took it as 02E4E30DAB but it adds a null byte first (IDK why).


The first output could be correct (it depends on the using), the second output (I think) is the good interpretation but it adds "00".


Try to convert : 02E4E30DAB (it should works, if you want to put it for every string, adds a if (str.length % 2 == 1) { str.insert(0,'0') }


Edited by mArTi
Link to comment

A correct Base64 string has not to end by == : it can end without anything, with a = or with ==.


Base64 encodes 6 bits by char, and we use bytes which are 8 bits. Each "=" means that we added 2 zero bits to fill the last base64 6-bits char.


 


Ex: you want to encode A (0x41) : 01000001. Base64 needs to encode on 6 chars :


First base 64 char will be the one that correspond to 010000 ("Q"). Now there's still "01" to encode but it's meant to be by 6 bits, so we add arbitrary "0000" to make it 6 bits : 010000 (again "Q"). So there we have QQ, but we need to tell that we put 4 bits to fill the last char, so we add 2 = : it will be "QQ==".


If you just put "QQ", it may means "010000 010000" which will give the byte A then a not complete byte (0000????). But usually base64 decoder are just taking bits by 8 and don't care of "=" (a not complete byte is nonsense, a good base64 decoder will output "A" for "QQ","QQ=" and "QQ==").


 


The funny thing is that we use this encoding usually in ascii, so the base64 characters are encoded on 8 bits while they have a 6-bits information, meaning that when we use it in ascii system we waste 2 bits/char.


Edited by mArTi
  • Like 1
Link to comment

Ok i found the solution,


 


Convert to a Base 64 and is it a bug in the  Miracl sdk


Thanks to all ,which have tried to help.


 


regards


Edited by ragdog
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...