Sign in to follow this  
Followers 0
Alek

Enigma

4 posts in this topic

#1 ·  Posted (edited)

well, i dont know much about enigma but i gave it a shot, so far it can only encrypt :) im still not sure how to make it decrypt (yet).

what i know about enigma is only the stuff i found on Wikipedia so please report back if there is something wrong with it.

i found it by random googleing :P

it creates new totaly random rollers (the things that creates the encryption) every time you start the script.

not sure if this was smart idea.

Edit: move the "rollers" to the correct part of the script (i think)

started working on the decrypting script, dosent work yet :blink:

#include <GUIConstants.au3>
Global $Roller[5][3]
            ;[number_of_Rollers][2]
            ;[$n][0] = then input|output alphabet
            ;[$n][1] = roller status. (how many times it has bin moved)
            ;[$n][2] = inputbox handle for the gui.

For $x = 0 To UBound($Roller,1)-1
    $Roller[$x][0] = _GenerateRandomalphabet() & "|" & _GenerateRandomalphabet()
    $Roller[$x][1] = 0
Next

$Form1 = GUICreate("", 395, 286, 193, 125)
$Edit1 = GUICtrlCreateInput("", 5, 25, 385, 89,$ES_MULTILINE)
$Label1 = GUICtrlCreateLabel("Input", 5, 5, 28, 17, $SS_SUNKEN)
$Edit2 = GUICtrlCreateInput("", 5, 190, 385, 89, $ES_MULTILINE)
$Label2 = GUICtrlCreateLabel("Output", 5, 170, 36, 17, $SS_SUNKEN)
$Button1 = GUICtrlCreateButton("Encrypt", 5, 120, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Reset Rollers", 85, 120, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Decrypt", 165, 120, 75, 25, 0)
GUICtrlSetState(-1,$GUI_DISABLE)
For $x = 0 To UBound($Roller,1)-1
    $Roller[$x][2] = GUICtrlCreateInput("1",(22*$x)+5,147,20,20)
Next

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetState($Button1,$GUI_DISABLE)
            $Text = GUICtrlRead($Edit1)
            $New_Text = _Enigma($Text,0)
            
            GUICtrlSetData($Edit2,$New_Text)
            For $x = 0 To UBound($Roller,1)-1
                GUICtrlSetData($Roller[$x][2],$Roller[$x][1]+1)
            Next
            
            GUICtrlSetState($Button1,$GUI_ENABLE)
        Case $Button2
            
            ;Reset the rollers, bad idea if we are going to decrypt it xD
            For $x = 0 To UBound($Roller,1)-1
                GUICtrlSetData($Roller[$x][2],$Roller[$x][1]+1)
                $Roller[$x][1] = 0
            Next
        Case $Button3
            GUICtrlSetState($Button3,$GUI_DISABLE)
            $Text = GUICtrlRead($Edit2)
            $New_Text = _Enigma($Text,1)
            
            GUICtrlSetState($Button3,$GUI_ENABLE)
            GUICtrlSetData($Edit1,$New_Text)
            For $x = 0 To UBound($Roller,1)-1
                GUICtrlSetData($Roller[$x][2],$Roller[$x][1]+1)
            Next
    EndSwitch
WEnd

Func _GenerateRandomalphabet()
    ;Thought it whould easyest to create a random alphabet, please tell me if it shouldent be random.
    Local $Return = ""
    For $x = 1 To 26
        Do
            $Random = Random(97,122,1)
        Until Not StringInStr($Return,Chr($Random))
        $Return &= Chr($Random)
    Next
    Return $Return
EndFunc

Func _Enigma($_String,$_Way=0) ;0 = encrypt, 1 = decrypt (not made yet xD)
    Local $Output_String = ""
    Switch $_Way
        Case 0
            
            ;write to the console what we are encrypting.
            ConsoleWrite("Encrypting: " & $_String & @CRLF)
            Do
                ;Get the chr we want to encrypt.
                $String = StringLeft($_String,1)
                
                ;Encrypt the shit.
                For $x = 0 To UBound($Roller,1)-1
                    
                    ;Split the input|output
                    $Split = StringSplit($Roller[$x][0],"|")
                    
                    ;find the chr on the input side + the amount of scrolling the rollers has done.
                    $Input = StringInStr($Split[1],$string)+$Roller[$x][1]
                    
                    ;check if the input is right, if not then correct it.
                    If $Input > 26 Then $Input -= 26
                    
                    ;Get the output chr.
                    $Output = StringSplit($Split[2],"")
                    
                    If $Input > UBound($Output)-1 Then MsgBox(0,"",$Input & " Wtf??" & @CRLF & StringLen($Split[1]))
                    
                    ;Set the string to the output chr to make the chr move on to the next roller.
                    ConsoleWrite("[" & $x+1 & "]: " & $string & "->" & $Output[$Input] & " ")
                    
                    ;Set the string so we can use it on the next roller.
                    $String = $Output[$Input]
                    
                Next
                    
                If $Roller[0][1] = 26 Then
                    For $x = 1 to UBound($Roller,1)-1
                        If $Roller[$x-1][1] = 26 Then
                            $Roller[$x][1] += 1
                            $Roller[$x-1][1] = 0
                        EndIf
                    Next
                Else
                    $Roller[0][1] += 1
                EndIf
                ;Put together the output string.
                $Output_String &= $String
                
                ;Create a new line in the console.
                ConsoleWrite(@CRLF)
                
                ;trim the _String to get the next chr.
                $_String = StringTrimLeft($_String,1)
            Until $_String = ""
            ConsoleWrite(@CRLF)
        Case 1
            
            ;Write to console what we are decrypting.
            ConsoleWrite("Decrypting: " & $_String & @CRLF)
            
            ;enter a do unil $_string = "" loop
            Do
                
                ;Get the text we want to decrypt
                $String = StringRight($_String,1)
                
                ;Loop trought all the rollers
                For $x = UBound($Roller,1)-1 to 0 Step -1
                    
                    ;Split the input|output of that roller. 
                    $Split = StringSplit($Roller[$x][0],"|")
                    
                    ;Get the input on the roller.
                    $Input = StringInStr($Split[2],$string) - $Roller[$x][1]
                    
                    ;Splitt the output, remeber we have changed the way the code enters and leaves the roller.
                    $Output = StringSplit($Split[1],"")
                    
                    If $Input < 0 Then $Input = 26-($Input*-1)
                    
                    ConsoleWrite("[" & $x+1 & "]: " & $string & "->" & $Output[$Input] & " ")
                    
                    $String = $Output[$Input]
                Next
                
                If $Roller[0][1] = 0 Then
                    For $x = 1 to UBound($Roller,1)-1
                        If $Roller[$x-1][1] = 0 Then
                            $Roller[$x][1] -= 1
                            $Roller[$x-1][1] = 26
                        EndIf
                    Next
                Else
                    $Roller[0][1] -= 1
                EndIf
                
                $Output_String &= $string
                ConsoleWrite(@CRLF)
                $_String = StringTrimRight($_String,1)
            Until $_String = ""
            
            ConsoleWrite(@CRLF)
    EndSwitch
    
    ;return the encrypted data.
    Return StringUpper($Output_String)
EndFunc
Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites



hey i had a question...its probably a stupid question but w/e ummm.... is it possible to create a script for a playfair cipher? if so could u help me get started? i know how to write one and use one by hand its just i dont know how to make it into a script

Share this post


Link to post
Share on other sites

hey i had a question...its probably a stupid question but w/e ummm.... is it possible to create a script for a playfair cipher? if so could u help me get started? i know how to write one and use one by hand its just i dont know how to make it into a script

Go along to the helpfile, or if your to lazy then go to rentacoder.com. This is not a place to request scripts!

Share this post


Link to post
Share on other sites

This is what I got with the sim on default:

Input:

Encoded output:

Decoded output:

Does it work now ?

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  
Followers 0