Jump to content
Sign in to follow this  
Morthawt

Alpha-only base26 conversion

Recommended Posts

Morthawt

I don't know if anyone else has done this with exclusively A-Z or would even need it but I have made a converter that can convert data into all alpha base 26.

So if you put "A" into it, by default you will see "CN" which represents the bits needed. However I originally wanted the ability to convert a hexadecimal based hash into this all alpha base26 so that I can attempt to create a serial code system using more than just 0-9 A-F. When I ran a hash through the original version of this I made it doubled in size because if a hash started with "A9" it would create a alpha base26 representation of the "A" and the "9", which was not intended.

So to remedy this what I did was include a parameter on the functions that can treat the encoded or decoded data as default data OR by setting the parameter to 1 it treats the content as a hash and instead of encoding each letter of the hash it reads the hash in groups of two, decodes the value and then encodes the same value in all alpha base 26.

I would like your opinions or thoughts on what I have done with this this. I had to rewrite the entire thing because I realised so many things during coding the old one that altering was more work than rewriting. I also have not included any checks yet to see if it is given non-hexadecimal in hex encoding/decoding mode.

;~ ____________________________________________________________________________
;~ Examples Examples Examples Examples Examples Examples Examples Examples

;~ Converting text or even file data into all alpha base 26
ConsoleWrite(Encode('Wesley G aka Morthawt') & @CRLF)

;~ Decoding the result of the previous operation.
ConsoleWrite(Decode('DJDXELEEDXERBGCTBGDTEDDTBGCZEHEKEMEADTEPEM') & @CRLF)

;~ Converting hexidecimal (Hashes for example) into all alpha base 26. This decodes the original hex and encodes the number as alpha base 26
ConsoleWrite(Encode('0355E038B02826AD203A913B9376DD6E52BD1A8A', 1) & @CRLF)

;~ Decoding the result of the previous operation.
ConsoleWrite(Decode('ADDHIQCEGUBOBMGRBGCGFPCHFREOINEGDEHHBAFI', 1) & @CRLF)

;~ /Examples Examples Examples Examples Examples Examples Examples Examples
;~ ____________________________________________________________________________


Func RawEncode($input = '', $mode = 0)
Local $list[27], $num, $result
For $a = 0 To 25
$list[$a] = Chr(65 + $a)
Next
$num = Asc($input)
If $mode Then $num = Number('0x' & $input)
$r = Floor(($num / 26))
If $num < 26 Then
$result = 'A' & $list[$num]
Else
$result = $list[$r]
$num -= (26 * $r)
$result &= $list[$num]
EndIf
Return $result
EndFunc ;==>RawEncode

Func RawDecode($input = '', $mode = 0)
Local $list[27], $num[3], $num, $result
For $a = 0 To 25
$list[$a] = Chr(65 + $a)
Next
$num[1] = StringMid($input, 1, 1)
$num[2] = StringMid($input, 2, 1)
For $a = 1 To 2
For $b = 0 To 25
$location = StringInStr($list[$b], $num[$a])
If $location Then
If $a = 1 Then
$result += 26 * $b
Else
$result += $b
If $mode = 0 Then
$result = Chr($result)
Else
$result = Hex(String($result), 2)
EndIf
Return $result
EndIf
EndIf
Next
Next
EndFunc ;==>RawDecode

Func Encode($input = '', $mode = 0)

For $a = 1 To StringLen($input)
Local $result
If $mode = 0 Then
$result &= RawEncode(StringMid($input, $a, 1), 0)
ElseIf $mode = 1 Then
$result &= RawEncode(StringMid($input, $a, 2), 1)
$a += 1
EndIf
Next
Return $result
EndFunc ;==>Encode

Func Decode($input = '', $mode = 0)
Local $result
For $a = 1 To StringLen($input) Step + 2
$result &= RawDecode(StringMid($input, $a, 2), $mode)
Next
Return $result

EndFunc ;==>Decode

So what do you think about the functioning of this / usefulness?

Thanks

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×