Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2020, 01:17
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 70
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 19 Times in 14 Posts
TempoMat Reputation: 6
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.
Reply With Quote
  #2  
Old 03-13-2020, 01:44
Kurapica's Avatar
Kurapica Kurapica is offline
VIP
 
Join Date: Jun 2009
Location: Archives
Posts: 137
Rept. Given: 13
Rept. Rcvd 129 Times in 37 Posts
Thanks Given: 28
Thanks Rcvd at 231 Times in 50 Posts
Kurapica Reputation: 100-199 Kurapica Reputation: 100-199
https://gist.github.com/JohannesMP/a911b7dc02bb0586e3111a0cbd2dc0e2

Credits to the original coder.
Reply With Quote
  #3  
Old 03-13-2020, 02:17
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 70
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 19 Times in 14 Posts
TempoMat Reputation: 6
Code snippet for converting a byteArray to Base34

Quote:
Originally Posted by Kurapica View Post
https://gist.github.com/JohannesMP/a911b7dc02bb0586e3111a0cbd2dc0e2

Credits to the original coder.
Thnaks for the link
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.
Reply With Quote
  #4  
Old 03-13-2020, 02:37
runio runio is offline
Friend
 
Join Date: Jul 2016
Location: Earth
Posts: 13
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 6
Thanks Rcvd at 10 Times in 7 Posts
runio Reputation: 0
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;
}
Reply With Quote
  #5  
Old 03-13-2020, 03:02
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 70
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 19 Times in 14 Posts
TempoMat Reputation: 6
@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
Reply With Quote
  #6  
Old 03-14-2020, 03:33
sendersu sendersu is offline
VIP
 
Join Date: Oct 2010
Posts: 848
Rept. Given: 324
Rept. Rcvd 216 Times in 110 Posts
Thanks Given: 168
Thanks Rcvd at 353 Times in 200 Posts
sendersu Reputation: 200-299 sendersu Reputation: 200-299 sendersu Reputation: 200-299
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
Reply With Quote
  #7  
Old 03-14-2020, 07:46
chants chants is online now
VIP
 
Join Date: Jul 2016
Posts: 576
Rept. Given: 7
Rept. Rcvd 35 Times in 21 Posts
Thanks Given: 501
Thanks Rcvd at 847 Times in 396 Posts
chants Reputation: 35
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.
Reply With Quote
  #8  
Old 03-14-2020, 10:23
chants chants is online now
VIP
 
Join Date: Jul 2016
Posts: 576
Rept. Given: 7
Rept. Rcvd 35 Times in 21 Posts
Thanks Given: 501
Thanks Rcvd at 847 Times in 396 Posts
chants Reputation: 35
DivMod or DivRem got autocorrected to diagram
Reply With Quote
  #9  
Old 03-14-2020, 20:33
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 70
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 19 Times in 14 Posts
TempoMat Reputation: 6
Quote:
Originally Posted by chants View Post
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.
I wanted to avoid using the BigNum library.

Quote:
Originally Posted by chants View Post
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.
Sorry for not making myself clearer.
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
The results were ok for a regular Base34 encoding.
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.

Quote:
Originally Posted by chants View Post
Now base 32 as a power of 2 would be a different story.
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.
Reply With Quote
The Following 2 Users Say Thank You to TempoMat For This Useful Post:
Artic (03-16-2020), chants (03-15-2020)
  #10  
Old 03-29-2020, 01:36
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 70
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 19 Times in 14 Posts
TempoMat Reputation: 6
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)
Regards,
TemPoMat
Reply With Quote
  #11  
Old 03-29-2020, 09:53
chants chants is online now
VIP
 
Join Date: Jul 2016
Posts: 576
Rept. Given: 7
Rept. Rcvd 35 Times in 21 Posts
Thanks Given: 501
Thanks Rcvd at 847 Times in 396 Posts
chants Reputation: 35
"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.
Reply With Quote
  #12  
Old 03-29-2020, 17:58
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 70
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 19 Times in 14 Posts
TempoMat Reputation: 6
Quote:
Originally Posted by chants View Post
"old" should be odd regardless congrats on solving.
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
Reply With Quote
The Following 2 Users Say Thank You to TempoMat For This Useful Post:
chants (03-29-2020), niculaita (03-29-2020)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


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


All times are GMT +8. The time now is 19:01.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX
( 1998 - 2020 )