DrOtosclerosi Posted January 2, 2019 Share Posted January 2, 2019 Hey everybody, I implemented an idea i had some years ago ( https://pastebin.com/ykmg676u ) . Basically, it's a cipher based on the Vigenere Cipher but with some differences. Here is a short explanation (in that pastebin is the original idea): This cipher is based on crossed substitution of the message and on simple substitution of the key. Here is the (working for me) code expandcollapse popup;======================================================================================== ;X-Sack by DrO ;Simple yet strong text message ciphering ;Roadmap: ;- Cipher / Decipher a text string (DONE) ;- Cipher / Decipher a whole text file (NEXT VERSION) ;- Cipher / Decipher any file through HEX manipulation (IN A GALAXY FAR, FAR AWAY) ;Based on my idea at: https://pastebin.com/ykmg676u ;Protected by Creative Commons By-Sa (https://creativecommons.org/licenses/by-sa/4.0/) ;Suggestions? Bugs? Write to drotosclerosi@gmail.com ;======================================================================================== #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=res\icona.ico #AutoIt3Wrapper_Outfile=XSacks_1_Beta.exe #AutoIt3Wrapper_Res_Fileversion=1.0 #AutoIt3Wrapper_Res_LegalCopyright=https://creativecommons.org/licenses/by-sa/4.0/ #AutoIt3Wrapper_Add_Constants=n #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> main() Func main() #Region ### START Koda GUI section ### Form=d:\xsack\forms\main.kxf $Main = GUICreate("X-Sack 1.0 by DrO - Enjoy your privacy", 540, 304, 192, 124) GUISetIcon(@ScriptDir & "\res\icona.ico", -1) $Message = GUICtrlCreateInput("Message", 16, 152, 153, 21) $Key = GUICtrlCreateInput("Key", 16, 208, 153, 21) $SecureKey = GUICtrlCreateInput("SecureKey", 240, 272, 65, 21) $Crypt = GUICtrlCreateButton("Crypt", 208, 136, 57, 105) $Ciphered = GUICtrlCreateInput("Ciphered", 368, 152, 153, 21) $CipheredKeyField = GUICtrlCreateInput("CipheredKeyField", 368, 208, 153, 21) $Decrypt = GUICtrlCreateButton("Decrypt", 280, 136, 49, 105) $Label1 = GUICtrlCreateLabel("X-SACK 1.0", 168, 8, 215, 81) GUICtrlSetFont(-1, 48, 400, 0, "Agency FB") $Label2 = GUICtrlCreateLabel("By DrO", 392, 64, 46, 22) GUICtrlSetFont(-1, 10, 400, 0, "Open Sans") $Halp = GUICtrlCreateButton("Halp", 472, 8, 51, 25) $Specifications = GUICtrlCreateButton("Specifications (on pastebin)", 200, 96, 139, 25) $Label3 = GUICtrlCreateLabel("Beta Version", 24, 8, 102, 32) GUICtrlSetFont(-1, 18, 400, 2, "Perpetua") $Label4 = GUICtrlCreateLabel("drotosclerosi@gmail.com", 16, 72, 125, 19) GUICtrlSetFont(-1, 10, 400, 0, "Perpetua") $Label5 = GUICtrlCreateLabel("Bugs? Missing features?", 16, 48, 129, 21) GUICtrlSetFont(-1, 11, 400, 0, "Perpetua") $Pic1 = GUICtrlCreatePic(@ScriptDir & "\res\88x31.bmp", 456, 272, 76, 28) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Crypt $CryptedMessage = "" ;Separate strings $ChMessage = StringSplit(GUICtrlRead($Message), "") $ChKey = StringSplit(GUICtrlRead($Key), "") $ChSecureKey = StringSplit(GUICtrlRead($SecureKey), "") ;Convert characters to ascii For $c = 1 To $ChMessage[0] $ChMessage[$c] = Asc($ChMessage[$c]) Next For $c = 1 To $ChKey[0] $ChKey[$c] = Asc($ChKey[$c]) Next For $c = 1 To $ChSecureKey[0] $ChSecureKey[$c] = Asc($ChSecureKey[$c]) Next ;Creates two arrays to divide the key Global $ChKeyFirstGroup[Round($ChKey[0] / 2) + 1] Global $ChKeySecondGroup[$ChKey[0] - Round($ChKey[0] / 2) + 1] ;Divides the key in two groups (1-3-5-7; 2-4-6) $d = 1 $e = 1 For $c = 1 To $ChKey[0] If IsInt($c / 2) Then $ChKeySecondGroup[$d] = $ChKey[$c] $d = $d + 1 Else $ChKeyFirstGroup[$e] = $ChKey[$c] $e = $e + 1 EndIf Next $ChKeyFirstGroup[0] = UBound($ChKeyFirstGroup) $ChKeySecondGroup[0] = UBound($ChKeySecondGroup) $KeyFirstGroupLimit = $ChKeyFirstGroup[0] - 1 $KeySecondGropuLimit = $ChKeySecondGroup[0] - 1 $d = 1 $e = 1 ;calculate the key checksum $KeyChecksum = 0 For $c = 1 To $ChKey[0] $KeyChecksum = $KeyChecksum + $ChKey[$c] Next ;encrypt For $c = 1 To $ChMessage[0] If Not IsInt($c / 2) Then If $e > $ChKeyFirstGroup[0] - 1 Then $e = 1 EndIf $ChMessage[$c] = $ChMessage[$c] + $ChKeyFirstGroup[$e] + $KeyChecksum $e = $e + 1 Else If $d > $ChKeySecondGroup[0] - 1 Then $d = 1 EndIf $ChMessage[$c] = $ChMessage[$c] + $ChKeySecondGroup[$d] + $KeyChecksum $d = $d + 1 EndIf While $ChMessage[$c] > 126 $ChMessage[$c] = $ChMessage[$c] - 126 WEnd If $ChMessage[$c] < 32 Then $ChMessage[$c] = $ChMessage[$c] + 31 EndIf $CryptedMessage = $CryptedMessage & Chr($ChMessage[$c]) Next GUICtrlSetData($Ciphered, $CryptedMessage) $CipheredKey = "" $n = 1 For $c = 1 To $ChKey[0] If $n > $ChSecureKey[0] Then $n = 1 EndIf $ChKey[$c] = $ChKey[$c] + $ChSecureKey[$n] While $ChKey[$c] > 126 $ChKey[$c] = $ChKey[$c] - 126 WEnd If $ChKey[$c] < 32 Then $ChKey[$c] = $ChKey[$c] + 31 EndIf $CipheredKey = $CipheredKey & Chr($ChKey[$c]) $n = $n + 1 Next GUICtrlSetData($CipheredKeyField, $CipheredKey) Case $Decrypt $UnCryptedMessage = "" $ChCipheredMessage = StringSplit(GUICtrlRead($Ciphered), "") $ChCipheredKey = StringSplit(GUICtrlRead($CipheredKeyField), "") $ChSecureKey = StringSplit(GUICtrlRead($SecureKey), "") For $c = 1 To $ChCipheredMessage[0] $ChCipheredMessage[$c] = Asc($ChCipheredMessage[$c]) Next For $c = 1 To $ChCipheredKey[0] $ChCipheredKey[$c] = Asc($ChCipheredKey[$c]) Next For $c = 1 To $ChSecureKey[0] $ChSecureKey[$c] = Asc($ChSecureKey[$c]) Next $UnCipheredKey = "" $n = 1 For $c = 1 To $ChCipheredKey[0] If $n > $ChSecureKey[0] Then $n = 1 EndIf $ChCipheredKey[$c] = $ChCipheredKey[$c] - $ChSecureKey[$n] If $ChCipheredKey[$c] < 32 Then $ChCipheredKey[$c] = $ChCipheredKey[$c] + 126 EndIf While $ChCipheredKey[$c] > 126 $ChCipheredKey[$c] = $ChCipheredKey[$c] - 31 WEnd $UnCipheredKey = $UnCipheredKey & Chr($ChCipheredKey[$c]) $n = $n + 1 Next GUICtrlSetData($CipheredKeyField, $UnCipheredKey) ;Creates two arrays to divide the key Global $ChCipheredKeyFirstGroup[Round($ChCipheredKey[0] / 2) + 1] Global $ChCipheredKeySecondGroup[$ChCipheredKey[0] - Round($ChCipheredKey[0] / 2) + 1] ;Divides the key in two groups (1-3-5-7; 2-4-6) $d = 1 $e = 1 For $c = 1 To $ChCipheredKey[0] If IsInt($c / 2) Then $ChCipheredKeySecondGroup[$d] = $ChCipheredKey[$c] $d = $d + 1 Else $ChCipheredKeyFirstGroup[$e] = $ChCipheredKey[$c] $e = $e + 1 EndIf Next $ChCipheredKeyFirstGroup[0] = UBound($ChCipheredKeyFirstGroup) $ChCipheredKeySecondGroup[0] = UBound($ChCipheredKeySecondGroup) $KeyFirstGroupLimit = $ChCipheredKeyFirstGroup[0] - 1 $KeySecondGropuLimit = $ChCipheredKeySecondGroup[0] - 1 $d = 1 $e = 1 ;calculate the key checksum $KeyChecksum = 0 For $c = 1 To $ChCipheredKey[0] $KeyChecksum = $KeyChecksum + $ChCipheredKey[$c] Next ;decrypt For $c = 1 To $ChCipheredMessage[0] If Not IsInt($c / 2) Then If $e > $ChCipheredKeyFirstGroup[0] - 1 Then $e = 1 EndIf $ChCipheredMessage[$c] = $ChCipheredMessage[$c] - $ChCipheredKeyFirstGroup[$e] - $KeyChecksum $e = $e + 1 Else If $d > $ChCipheredKeySecondGroup[0] - 1 Then $d = 1 EndIf $ChCipheredMessage[$c] = $ChCipheredMessage[$c] - $ChCipheredKeySecondGroup[$d] - $KeyChecksum $d = $d + 1 EndIf While $ChCipheredMessage[$c] < 32 $ChCipheredMessage[$c] = $ChCipheredMessage[$c] + 126 WEnd While $ChCipheredMessage[$c] > 126 $ChCipheredMessage[$c] = $ChCipheredMessage[$c] - 31 WEnd $UnCryptedMessage = $UnCryptedMessage & Chr($ChCipheredMessage[$c]) Next GUICtrlSetData($Ciphered, $UnCryptedMessage) Case $Halp MsgBox(0, "How to use", "CRYPT:" & @CRLF & "Insert your message, your key and the securekey used to protect your key in the fields at the right and at the bottom, then press 'Crypt'" & @CRLF & "DECRYPT:" & @CRLF & "Do the same, but in the fields at the left and at the bottom.") Case $Specifications Run("https://pastebin.com/ykmg676u") Case $GUI_EVENT_CLOSE MsgBox(0, "42", "So Long, and Thanks for All the Fish", 3) Exit EndSwitch WEnd EndFunc ;==>main Theoretically, I would like to implement an encryption of files (like substituting hex values instead of ascii). Let me know what you think about it Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now