Files
harbour-core/contrib/hbmisc/tests/bubbleb.prg
Viktor Szakats 58faf91453 2016-01-14 19:17 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com)
* *
    % remove brandings and homepage [1] from copyright header. Pass 1 - using script.
      [1] nobody has access to it anymore AFAIK - and it's also just
          a redirect since long
    ! update url in copyright header
    ; this should make the diff between 3.4 and 3.2 easier to manage
2016-01-14 19:18:17 +01:00

80 lines
1.7 KiB
Plaintext

/*
*
* Copyright 2010 Viktor Szakats (vszakats.net/harbour)
*
*/
#require "hbmisc"
PROCEDURE Main()
? BubbleBabbleEncode_prg( "" )
? BubbleBabbleEncode( "" )
? "xexax"
? BubbleBabbleEncode_prg( "1234567890" )
? BubbleBabbleEncode( "1234567890" )
? "xesef-disof-gytuf-katof-movif-baxux"
? BubbleBabbleEncode_prg( "Pineapple" )
? BubbleBabbleEncode( "Pineapple" )
? "xigak-nyryk-humil-bosek-sonax"
? BubbleBabbleEncode_prg( "hello" )
? BubbleBabbleEncode( "hello" )
? BubbleBabbleEncode_prg( "vszakats" )
? BubbleBabbleEncode( "vszakats" )
RETURN
/* Harbour implementation */
FUNCTION BubbleBabbleEncode_Prg( cString )
LOCAL vo := "aeiouy"
LOCAL co := "bcdfghklmnprstvzx"
LOCAL cResult := "x"
LOCAL i
LOCAL byte1, byte2
LOCAL nSeed := 1
i := 1
DO WHILE .T.
IF i > Len( cString )
cResult += ;
SubStr( vo, nSeed % 6 + 1, 1 ) + ;
SubStr( co, 16 + 1, 1 ) + ;
SubStr( vo, nSeed / 6 + 1, 1 )
EXIT
ENDIF
byte1 := Asc( SubStr( cString, i, 1 ) )
cResult += ;
SubStr( vo, ( ( hb_bitAnd( hb_bitShift( byte1, -6 ), 3 ) + nSeed ) % 6 ) + 1, 1 ) + ;
SubStr( co, hb_bitAnd( hb_bitShift( byte1, -2 ), 15 ) + 1, 1 ) + ;
SubStr( vo, ( ( hb_bitAnd( byte1, 3 ) + ( nSeed / 6 ) ) % 6 ) + 1, 1 )
IF i + 1 > Len( cString )
EXIT
ENDIF
byte2 := Asc( SubStr( cString, i + 1, 1 ) )
cResult += ;
SubStr( co, hb_bitAnd( hb_bitShift( byte2, -4 ), 15 ) + 1, 1 ) + ;
"-" + ;
SubStr( co, hb_bitAnd( byte2, 15 ) + 1, 1 )
nSeed := ( nSeed * 5 + byte1 * 7 + byte2 ) % 36
i += 2
ENDDO
RETURN cResult + "x"