#1
|
|||
|
|||
Code snippet for Base34 Encoding
Hi,
Does anyone has a code snippet for Base34 encoder/decoder preferably in x86 asm, C, C++, classic Delphi to share? Thanks PS: In case anyone is wondering why I am posting here instead of in the request forum; well it is because I was inform that I don't have any permission to post there, when I tried to start a new thread. |
#2
|
||||
|
||||
https://gist.github.com/JohannesMP/a911b7dc02bb0586e3111a0cbd2dc0e2
Credits to the original coder. |
#3
|
|||
|
|||
Code snippet for converting a byteArray to Base34
Quote:
Howover I have tried that and many others already and this particular one does not work for me, because that code snippet is for bases 2...36. I forgot to state in my first post that the search is for conversion from ByteArray to Base34. So to use this code snippet one has to first convert the byteArray (==BigNumber) to Binary or Base10 and then to Base34. Alternative suggestion is to use BigInteger Library for the division, which I thought I could avoid. |
#4
|
|||
|
|||
https://en.wikipedia.org/wiki/Base36
Base34 is (0-9), (A-X) Example code converted from Base36 Code:
#include <stdio.h> #include <string.h> #include <stdlib.h> static char *base34enc(long unsigned int value) { char base34[34] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWX"; char buffer[14]; unsigned int offset = sizeof(buffer); buffer[--offset] = '\0'; do { buffer[--offset] = base34[value % 34]; } while (value /= 34); return strdup(&buffer[offset]); } static long unsigned int base34dec(const char *text) { return strtoul(text, NULL, 34); } int main() { printf("The number(unsigned long integer) is %lu\n", base34dec("ABCDEF")); return 0; } |
#5
|
|||
|
|||
@runio
If I am not mistaken the unsigned long integer type should be in the range [0, +18,446,744,073,709,551,615]. Therefore the code snippet will not work for a number like B9DDE784B6FFC653DFEC3E94D6B610 (965075674130144583043497186064512528) or larger. Regards |
#6
|
|||
|
|||
One need to say "long long" in order to get that 18....... super massive number
otherwise its just 4^32 (4G) limit https://en.wikipedia.org/wiki/C_data_types |
#7
|
|||
|
|||
This is pretty basic computer science stuff here. Converting between data types and bases. Since you appear to want to use bignums though the best we can give you is pseudo code for languages like C#or Java.
The implementation details of bignum which likely converts the byte array first into an int array for efficient computation are another question altogether. Though implementing a bignum library from scratch is not too difficult and a good learning experience. So the byte array practically speaking is useless. You need division and modulo by 34 so no tricks there. Now base 32 as a power of 2 would be a different story. In conclusion get or make a bignum library, convert your byte array, and to be efficient make a diagram function and loop on it as you do the conversion. Gor decoding same thing just multiply by 34 and add. |
#8
|
|||
|
|||
DivMod or DivRem got autocorrected to diagram
|
#9
|
|||
|
|||
Quote:
Quote:
I am familier with the use of BigNumber libraries. For instances I have been able to factorize some modulus N numbers upto 512 Bits and with the help of an assembler code Ziggy (thanks a bunch for that) provided me some years ago, been able to keygen a lot of apps with the use of one or a combination of Drizz, Fleur or FGIntRSA libraries. So on 12.03.2020 after my last post, I did the rough asm implementation with Fleur's BigNum library in the form Code:
Base34CharSet='ABCDEFGHIJKLMNPQRSTUVWXYZ123456789' ; as an example bnX ;== The BigNumber bnY ;== TheBase in this case 34 bnRem .repeat BigDiv32, bnX, bnY, bnRem, 0 Out(i)=Base34CharSet(bnRem) inc i .until bnX=0 I forgot to give a feedback after that. Sorry for that The results however did not correspond to the samples of Base34Strings I fed in to the Progi to decode. It is a simple RSA 120-Bit with what now looks like a home breed Base342ByteArray decoding routine. Yes bases with powers of 2 are relative easy to implement. An example will be to convert the ByteArray to binary bits and then convert the resulted bits in groups (size of a group corresponding to the nibble size of the base) for the indices to access the BaseXCharSet. I must applaud the author for only including the Base34 decoding algorithm in his app and also not using those default ciphers in the BigNum library he used for the asymmetric encryption. I will continue to analyze his decoding algorithm to see if I can somehow be able to reverse it. Thanks again to all. |
#10
|
|||
|
|||
Resolved:Code snippet for Base34 Encoding
Just want to give a feedback on how I resolved the problem:
There was a small trick I didn’t pay much attention to at the beginning. The protection is an RSA-120 bits Sign algo for generating and then Base34 encoding the result to give key. Now the trick with the decoding was what kept me trying different Base34 Encode/Decode routines. This is the procedure used for generating or needed to create a valid key: Code:
1. RSASign(15 ByteString) =>Res1 The 15.Byte is a checksum of the first 14 Bytes with the bytes at position 1 and 3 interchanged 2. ByteArray2Binary(Res1) =>Res2 3. First take and group the bits at the old positions of Res2 and then concat with the bits at the even positions=>Res3 4. RegistrationKey=Binary2Base34(Res3) TemPoMat |
#11
|
|||
|
|||
"ByteArray2Binary" sounds redundant as an array of bytes or words or hints, etc are already in binary form. Expansion to 1 byte per bit is pointless and just something a procedural oriented programmer would go for since its unnecessary unless some special vectorized code is utilized. Probably a lot of masterful bit twiddlers in the asm and RE world
"old" should be odd regardless congrats on solving. |
#12
|
|||
|
|||
Yes it was supposed to be odd and not old.
Sorry for the mistake. Nevertheless I believe the sentence was still understandable, given that in the same context was the phrase "concat with the bits at the even positions" Cheers and everyone stay safe. TemPoMat |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Strange string encoding in C code | dila | Source Code | 10 | 04-10-2018 03:45 |
Code timing snippet | Git | Developer Section | 5 | 01-05-2018 02:05 |
Any ideas about executing phpinfo() in this code snippet | XnHandt | General Discussion | 0 | 12-28-2012 00:46 |
How to execute a snippet of code before the main execution! | Android | General Discussion | 8 | 10-04-2006 01:22 |