Bifid cipher: Difference between revisions

Content added Content deleted
No edit summary
mNo edit summary
Line 718: Line 718:
=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
<syntaxhighlight lang="futurebasic">
clear local fn recode( u as CFStringRef, code as CFStringRef ) as CFStringRef
clear local fn recode( t as CFStringRef, code as CFStringRef ) as CFStringRef
CFStringRef s = @""
CFStringRef s = @""
Short i, k, w = sqr( len( code ) )
Short i, k, w = sqr( len( code ) )
for i = 0 to len( u ) - 1 step 2
for i = 0 to len( t ) - 1 step 2
k = intval( mid( u, i, 2 ) ) // Get ‘coordinates’ of char in code string
k = intval( mid( t, i, 2 ) ) // Get ‘coordinates’ of char in code string
k = w * ( k / 10 ) + k mod 10
k = w * ( k / 10 ) + k mod 10
s = fn StringByAppendingString( s, mid( code, k, 1 ) )
s = fn StringByAppendingString( s, mid( code, k, 1 ) )
Line 732: Line 732:
//
//


clear local fn encode( t as CFStringRef, code as CFStringRef ) as CFStringRef
clear local fn encode( s as CFStringRef, code as CFStringRef ) as CFStringRef
CFStringRef a = @"", b = @"", c
CFStringRef a = @"", b = @"", c
CFMutableStringRef s = fn MutableStringWithString( t )
Short i, k, w = sqr( len( code ) )
Short i, k, w = sqr( len( code ) )
if w == 5 then MutableStringReplaceAllOccurrencesOfString( s, @"J", @"I" )
if w == 5 then s = fn StringByReplacingOccurrencesOfString( s, @"J", @"I" )
print s
print s