Jump to content

Secret Message


JustinReno
 Share

Recommended Posts

I made another...

;Base 96 and Base 10 (2)        Error = 4%
;Base 224 (3) and Base 26 (5)   Error = 5.4%

Global $gui, $edit, $base10, $base26, $decode
Global $string, $char, $continue = True, $temp, $temp2

$gui = GUICreate("Simple Encoder",580,500)
GUISetFont(12,400,0,"Arial")
$edit = GUICtrlCreateEdit("",10,10,560,440,0x200044)
$base10 = GUICtrlCreateButton("Encode 10",10,460,180,30)
$base26 = GUICtrlCreateButton("Encode 26",200,460,180,30)
$decode = GUICtrlCreateButton("Decode",390,460,180,30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $base10
            GUICtrlSetState($edit,128)
            $string = GUICtrlRead($edit)
            $continue = True
            For $z = 1 To StringLen($string)
                $char = Asc(StringMid($string,$z,1))
                If $char < 32 Or $char > 127 Then
                    GUICtrlSetData($edit,@CRLF&@CRLF&"All characters must be within the ASCII range of 32 to 127 for Base 10 encoding.",0)
                    $continue = False
                    ExitLoop
                EndIf
            Next
            If $continue Then
                GUICtrlSetData($edit,0)
                For $z = 1 To StringLen($string)
                    $char = String(Asc(StringMid($string,$z,1))-32)
                    If StringLen($char) = 1 Then
                        GUICtrlSetData($edit,"0" & $char,0)
                    Else
                        GUICtrlSetData($edit,$char,0)
                    EndIf
                Next
            EndIf
            GUICtrlSetState($edit,64)
        Case $base26
            GUICtrlSetState($edit,128)
            $string = GUICtrlRead($edit)
            $continue = True
            For $z = 1 To StringLen($string)
                $char = Asc(StringMid($string,$z,1))
                If $char < 32 Then
                    GUICtrlSetData($edit,@CRLF&@CRLF&"All characters must be within the ASCII range of 32 to 255 for Base 26 encoding.",0)
                    $continue = False
                    ExitLoop
                EndIf
            Next
            If $continue Then
                GUICtrlSetData($edit,"A")
                If StringLen($string)-3*Int(StringLen($string)/3) = 1 Then
                    $string &= "  "
                ElseIf StringLen($string)-3*Int(StringLen($string)/3) Then
                    $string &= " "
                EndIf
                For $z = 1 To StringLen($string) Step 3
                    $temp = 50176*(Asc(StringMid($string,$z,1))-32)+224*(Asc(StringMid($string,$z+1,1))-32)+(Asc(StringMid($string,$z+2,1))-32)
                    For $y = 4 To 0 Step -1
                        $temp2 = Int($temp/26^$y)
                        GUICtrlSetData($edit,Chr($temp2+65),0)
                        $temp -= $temp2*26^$y
                    Next
                Next
                
            EndIf
            GUICtrlSetState($edit,64)
        Case $decode
            GUICtrlSetState($edit,128)
            $string = GUICtrlRead($edit)
            GUICtrlSetData($edit,"")
            $char = StringLeft($string,1)
            $string = StringTrimLeft($string,1)
            If $char = "0" Then
                For $z = 1 To StringLen($string)-1 Step 2
                    GUICtrlSetData($edit,Chr(StringMid($string,$z,2)+32),0)
                Next
            ElseIf $char = "A" Then
                For $z = 1 To StringLen($string)-4 Step 5
                    $temp = 0
                    For $y = 4 To 0 Step -1
                        $temp += 26^$y*(Asc(StringMid($string,$z+4-$y,1))-65)
                    Next
                    For $y = 2 To 0 Step -1
                        $temp2 = Int($temp/224^$y)
                        GUICtrlSetData($edit,Chr($temp2+32),0)
                        $temp -= $temp2*224^$y
                    Next
                Next
            Else
                GUICtrlSetData($edit,@CRLF&@CRLF&"Invalid Code",0)
            EndIf
            GUICtrlSetState($edit,64)
    EndSwitch
    ;check the current ascii range to test compatibility, eliminating Line 26 and 50
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...