Jump to content
Sign in to follow this  
iamtheky

Gronsfeld Cipher

Recommended Posts

The CTF we were playing this evening had a gronsfeld cipher, so here is my first stab at a function that would solve it. Due to the way I am rolling through the alphabet all characters must be uppercase (and specials removed or stripped in the func, i opted for removing them manually for example purposes), any improvements are welcome.

local $aTestKey[8] = [0,7,2,7,1,9,7,8]

$aTestStrCreate = stringsplit(stringupper("ICECTFIDONTTHINKGRONSFELDLIKESMONDAYS") , "" , 2)

$aTestStrSolve = stringsplit(stringupper("IjgJUOPLOUVAIRUSGYQUTOLTDSKRFBTWNKCFT") , "", 2)


ConsoleWrite(_GronsfeldCipher($aTestKey , $aTestStrCreate , 0) & @LF)
ConsoleWrite(_GronsfeldCipher($aTestKey , $aTestStrSolve , 1) & @LF)


Func _GronsfeldCipher($aKey , $aStr , $action)  ; 0 = Create , 1 = Solve

$k = -1
$aOut = ""

If $action = 1 Then

For $i = 0 to ubound($astr) - 1
    $k+=1
     If asc($astr[$i]) - $aKey[$k] < 65 Then
         $aOut &= chrw(asc($astr[$i]) + 26 - $aKey[$k])
        Else
         $aOut &= chrw(asc($astr[$i]) - $aKey[$k])
     EndIf
    If $k = ubound($aKey) - 1 Then $k = -1
Next

Else

For $i = 0 to ubound($astr) - 1
    $k+=1
     If asc($astr[$i]) + $aKey[$k] > 90 Then
         $aOut &= chrw(asc($astr[$i]) - 26 + $aKey[$k])
        Else
         $aOut &= chrw(asc($astr[$i]) + $aKey[$k])
     EndIf
    If $k = ubound($aKey) - 1 Then $k = -1
Next

EndIf

return $aOut

EndFunc

  garfeld.png.b61578fa59401853d9d61dc1e8eaaa77.png

Edited by iamtheky
improvements

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

added to the Func so you can both create and solve them, suppose I'll get around to fixing it to add lowercase support as well.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...