iamtheky Posted September 8, 2018 Share Posted September 8, 2018 (edited) 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. expandcollapse popuplocal $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 Edited September 10, 2018 by iamtheky improvements ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
iamtheky Posted September 10, 2018 Author Share Posted September 10, 2018 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. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) 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