Hi,
My current situation:
After hashing I get a bytearray of 24 bytes,
normally one would just convert it to hex which is easy.
But now I have to convert it to the base of 36 (0-9 + A-Z),
which is not so easy anymore.
Is there a simple way to do this?
The idea I have come up with seems a bit complex for the problem:
[CSharp]public static byte[] ByteMultiply(byte[] b, int x)
public static byte[] ByteDivision(byte[] b, int x)
public static byte[] ByteAdd(byte[] b, int x)
public static byte[] ByteSubstract(byte[] b1, byte[] b2)
public static bool ByteEqual(byte[] b, int x)
public static bool ByteGreaterThan(byte[] b1, byte[] b2)
public static string ToString(byte[] b, int baseNumber) {
byte[] baseDigit = new byte[0];
string baseStr = "";
baseDigit = ByteAdd(baseDigit, 1);
while(true) {
baseDigit = ByteMultiply(baseDigit, baseNumber);
if(ByteGreaterThan(baseDigit, b)) break;
}
baseDigit = ByteDivision(baseDigit, baseNumber);
int count;
while(!ByteEqual(baseDigit, 1)){
count = 0;
while(ByteGreaterThan(b, baseDigit)) {
b = ByteSubstract(b, baseDigit);
count++;
}
baseStr += map[count];
baseDigit = ByteDivision(baseDigit, baseNumber);
}
count = 0;
while(ByteGreaterThan(b, baseDigit)) {
b = ByteSubstract(b, baseDigit);
count++;
}
baseStr += map[count];
return baseStr;
}[/CSharp]
Ah, oh well the '[' issue in the CSharp tag is still around.
My current situation:
After hashing I get a bytearray of 24 bytes,
normally one would just convert it to hex which is easy.
But now I have to convert it to the base of 36 (0-9 + A-Z),
which is not so easy anymore.
Is there a simple way to do this?
The idea I have come up with seems a bit complex for the problem:
[CSharp]public static byte[] ByteMultiply(byte[] b, int x)
public static byte[] ByteDivision(byte[] b, int x)
public static byte[] ByteAdd(byte[] b, int x)
public static byte[] ByteSubstract(byte[] b1, byte[] b2)
public static bool ByteEqual(byte[] b, int x)
public static bool ByteGreaterThan(byte[] b1, byte[] b2)
public static string ToString(byte[] b, int baseNumber) {
byte[] baseDigit = new byte[0];
string baseStr = "";
baseDigit = ByteAdd(baseDigit, 1);
while(true) {
baseDigit = ByteMultiply(baseDigit, baseNumber);
if(ByteGreaterThan(baseDigit, b)) break;
}
baseDigit = ByteDivision(baseDigit, baseNumber);
int count;
while(!ByteEqual(baseDigit, 1)){
count = 0;
while(ByteGreaterThan(b, baseDigit)) {
b = ByteSubstract(b, baseDigit);
count++;
}
baseStr += map[count];
baseDigit = ByteDivision(baseDigit, baseNumber);
}
count = 0;
while(ByteGreaterThan(b, baseDigit)) {
b = ByteSubstract(b, baseDigit);
count++;
}
baseStr += map[count];
return baseStr;
}[/CSharp]
Ah, oh well the '[' issue in the CSharp tag is still around.