Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Extremely simple encryption and decryption of a text string using the RND function.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin/PBCC Extremely simple encryption and decryption of a text string using the RND function.

    ' Extremely simple encryption and decryption of a text string using the RND function.
    ' You can vary the theme endlessly by using even more complex expressions with the RND function.
    ' These functions are fast, and if you can keep the randomize values hidden, the encrypted
    ' text is difficult to decipher.
    Code:
    ' Extremely simple encryption and decryption of a text string using the RND function.
    ' You can vary the theme endlessly by using even more complex expressions with the RND function.
    ' These functions are fast, and if you can keep the randomize values hidden, the encrypted
    ' text is difficult to decipher. :)
    
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        LOCAL i, j AS LONG
        LOCAL s AS STRING
        s = "Isaac became a hurricane Tuesday that could flood the " + _
            "coasts of four states with storm surge and heavy rains " + _
            "on its way to New Orleans, where residents hunkered down " + _
            "behind levees fortified after Katrina struck seven years ago this week."
        MSGBOX s
    
        ' encrypt
        RANDOMIZE 132452             ' should be the same for
        RANDOMIZE RND(5, 3785265)    ' encryption and decryption
        FOR i = 1 TO LEN(s)
            ' You should have opposite + and - signs in
            ' in the encryption and decryption functions.
            j = ASC(s, i) + RND(5, RND(9, RND(12, 20)))*RND(1, 2) ' + sign
            MID$(s, i, 1) = CHR$(j)
        NEXT
        MSGBOX s
    
        ' decrypt
        RANDOMIZE 132452
        RANDOMIZE RND(5, 3785265)
        FOR i = 1 TO LEN(s)
            j = ASC(s, i) - RND(5, RND(9, RND(12, 20)))*RND(1, 2) ' - sign
            MID$(s, i, 1) = CHR$(j)
        NEXT
        MSGBOX s
    
    END FUNCTION

  • #2
    The same could be said for:

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        LOCAL i, j AS LONG
        LOCAL s AS STRING
        s = "Isaac became a hurricane Tuesday that could flood the " + _
            "coasts of four states with storm surge and heavy rains " + _
            "on its way to New Orleans, where residents hunkered down " + _
            "behind levees fortified after Katrina struck seven years ago this week."
        MSGBOX s
    
        ' encrypt
        RANDOMIZE 1             ' should be the same for
                                     ' encryption and decryption
        FOR i = 1 TO LEN(s)
            ' You should have opposite + and - signs in
            ' in the encryption and decryption functions.
            j = ASC(s, i) + RND(5,40) ' + sign
            MID$(s, i, 1) = CHR$(j)
        NEXT
        MSGBOX s
    
        ' decrypt
        RANDOMIZE 1
        FOR i = 1 TO LEN(s)
            j = ASC(s, i) - RND(5, 40) ' - sign
            MID$(s, i, 1) = CHR$(j)
        NEXT
        MSGBOX s
    END FUNCTION
    If you keep the initial seed hidden, this has exactly the same degree of difficulty to decipher. Which incidentally, isn't very hard at all - you are effectively applying a the same simple mask to every string.
    --
    [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
    PNG Domain Hosting[/URL]

    Comment


    • #3
      PowerBasic’s pseudo random number sequence does not repeat until after a series of 2^32 =
      4294967296 numbers. For a given seed value, RND always returns the same sequence of values.
      Even if you can figure out where in the sequence you are, it should be possible to obscure things by
      manipulating the random numbers using various functions like If Then Else, *, /, +, -, \, MOD, and loops.
      Last edited by Erik Christensen; 29 Aug 2012, 01:33 PM.

      Comment


      • #4
        Agree, I wrote the original version of this PBCC program 20 years ago in PBDOS. It can encrypt/decrypt any type of file using a case sensitive, 9 characters long, keyword.

        Code:
         
        'PBCC 6 Program, Manuel Valdes
        #COMPILE EXE
        #OPTION ANSIAPI
        #DIM ALL
         
        FUNCTION PBMAIN () AS LONG
         LOCAL OP2$(),OP%,SO$
         CURSOR OFF
         COLOR 7,1
         CLS
         DIM OP2$(2)
         CONSOLE NAME "ENCRYPTA"
         OP2$(1)="  Encrypt     "
         OP2$(2)="  Decrypt     "
         OP%=1
         CALL FRAME()
         DO
          LOCATE 15,12:PRINT OP2$(1)
          LOCATE 16,12:PRINT OP2$(2)
          COLOR 4,7
          SELECT CASE OP%
           CASE=1
            LOCATE 15,12:PRINT OP2$(1)
           CASE=2
            LOCATE 16,12:PRINT OP2$(2)
           END SELECT
          COLOR 7,1
          SO$=WAITKEY$
          IF MID$(SO$,2,1)=CHR$(72) THEN
           IF OP%=1 THEN
            OP%=2
           ELSE
            DECR OP%
           END IF
          ELSEIF MID$(SO$,2,1)=CHR$(80) THEN
           IF OP%=2 THEN
            OP%=1
           ELSE
            INCR OP%
           END IF
          ELSEIF SO$=CHR$(13) THEN
           CALL ENCRY(OP%)
           LOCATE 10,32:PRINT SPC(40)
           LOCATE 12,32:PRINT SPC(10)
           LOCATE 16,33:PRINT "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°"
           LOCATE 18,32:PRINT "    Esc - Exit     ";
          END IF
          IF SO$=CHR$(27) THEN EXIT
         LOOP
         COLOR 7,0
         CLS
        END FUNCTION
         
        SUB ENCRY(OP%)
         LOCAL ARCHE$,CE$,CRS%,R!,LL$,L$,OFS%,S&&,C?,CH%,ST&&
         ARCHE$=""
         CALL FORMATTED_INPUT(32,10,40,ARCHE$,1,0,CRS%)
         LOCATE 10,32:PRINT MID$(ARCHE$+STRING$(40 ,32),1,40)
         IF ARCHE$<>"" THEN
          CALL FORMATTED_INPUT(32,12,9,CE$,1,0,CRS%)
          LOCATE 12,32:PRINT MID$(CE$+STRING$(9,32),1,9)
          CE$=MID$(CE$+STRING$(9,32),1,9)
          CALL EKEY(CE$,R!)
          LOCATE 18,32
          COLOR 15,1
          PRINT "   Please wait...";
          COLOR 7,1
          RANDOMIZE R!
          OPEN ARCHE$ FOR BINARY AS #1
          GET$ #1,LOF(1),LL$
          IF LOF(1) THEN
           ST&&=LOF(1)\36
           FOR S&&=1 TO LOF(1)
            CH%=RND(1,7)
            C?=CVBYT(MID$(LL$,S&&,1))
            IF OP%=1 THEN
             ROTATE LEFT C?,CH%
            ELSE
             ROTATE RIGHT C?,CH%
            END IF
            MID$(LL$,S&&,1)=MKBYT$(C?)
            IF S&& MOD ST&& = 0 THEN
             LOCATE 16,33:PRINT STRING$(37*S&&\LOF(1),219)
            END IF
           NEXT
           SEEK #1,1
           PUT$ #1,LL$
           CLOSE 1
          ELSE
           CLOSE 1
          END IF
         END IF
        END SUB
         
        SUB FRAME()
         LOCAL H%
         LOCATE 6,7:PRINT STRING$(68,32)
         LOCATE 7,7:PRINT CHR$(32);CHR$(218);STRING$(64,196);CHR$(191);CHR$(32)
         FOR H%=8 TO 17
          LOCATE H%,7:PRINT CHR$(32);CHR$(179);STRING$(64,32);CHR$(179);CHR$(32)
         NEXT H%
         LOCATE 18,7:PRINT CHR$(32);CHR$(192);STRING$(64,196);CHR$(217);CHR$(32)
         LOCATE 19,7:PRINT STRING$(68,32)
         LOCATE 14,11:PRINT "ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿"
         LOCATE 15,11:PRINT "³              ³"
         LOCATE 16,11:PRINT "³              ³"
         LOCATE 17,11:PRINT "ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
         LOCATE  7,27:PRINT "  F I L E   E N C R Y P T I O N  "
         LOCATE 8,64:PRINT "M.Valdes"
         LOCATE 10,11:PRINT "   File to Process : ";
         LOCATE 12,11:PRINT "   Encryption Key  : ";
         LOCATE 14,31:PRINT "ÚÄÄÄÄÄÄÄÄÄÄ  P r o g r e s s  ÄÄÄÄÄÄÄÄÄ¿"
         LOCATE 15,31:PRINT "³ 0%               50%             100%³"
         LOCATE 16,31:PRINT "³ °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° ³"
         LOCATE 17,31:PRINT "ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"
         LOCATE 18,32:PRINT "   Esc - Exit     ";
        END SUB
         
        SUB EKEY(CE$,R!)
         LOCAL D1%,D2%,D3%,D4%,D5%,D6%,D7%,D8%,D9%
         D1%=ASC(MID$(CE$,1,1))
         D2%=ASC(MID$(CE$,2,1))
         D3%=ASC(MID$(CE$,3,1))
         D4%=ASC(MID$(CE$,4,1))
         D5%=ASC(MID$(CE$,5,1))
         D6%=ASC(MID$(CE$,6,1))
         D7%=ASC(MID$(CE$,7,1))
         D8%=ASC(MID$(CE$,8,1))
         D9%=ASC(MID$(CE$,9,1))
         R!=D1%/3+D2%/5+D3%/7+D4%/9+D5%/11+D6%/13+D7%/15+D8%/17+D9%/19
        END SUB
         
        SUB FORMATTED_INPUT(XF%,YF%,LF%,CAD$,FT%,D%,CRS%)
         LOCAL ASTR$(),I%,L%,PF%,CH$,CH1$
         DIM ASTR$(80)
         CRS%=0
         ASTR$(0)=CHR$(0)
         CAD$=CAD$+STRING$(LF%,32)
         FOR I% = 1 TO LF%
          ASTR$(I%) = MID$(CAD$,I%,1)
         NEXT
         L% = LF%
         WHILE ASTR$(L%) = CHR$(32)
          DECR L%
         WEND
         IF L% < 0 THEN L% = 0
         PF% = L%
         IF PF%=0 THEN PF%=1
         DO
          CH1$ = CHR$(0)
          LOCATE YF%,XF%
          FOR I% = 1 TO LF%
           IF I% = PF% THEN
            COLOR 15,4
           ELSE
            COLOR 15,3
           END IF
           IF FT%=5 THEN
            PRINT CHR$(42);
           ELSE
            PRINT ASTR$(I%);
           END IF
           IF FT%=2 THEN
            IF I%=2 OR I%=4 THEN
             COLOR 15,3
             PRINT "/";
            END IF
           ELSEIF FT%=3 AND I%=LF%-D% THEN
            COLOR 15,3
            IF D%>0 THEN PRINT CHR$(46);
           ELSEIF FT%=4 THEN
            IF I%=2 THEN
             COLOR 15,3
             PRINT ":";
            END IF
           END IF
          NEXT
          DO UNTIL INSTAT
          LOOP
          CH$ = INKEY$
          IF LEN(CH$) = 1 THEN
           SELECT CASE CH$
            CASE CHR$(8)
             FOR I% = PF% TO L%
              ASTR$(I%-1) = ASTR$(I%)
             NEXT
             IF PF% > 1 THEN DECR PF%
             IF L% > 1 THEN
              ASTR$(L%) = CHR$(32)
              DECR L%
             END IF
            CASE CHR$(27)
             COLOR 15,7
             EXIT SELECT
            CASE CHR$(9)
             COLOR 15,7
             EXIT SELECT
            CASE  > CHR$(30)
             IF L% < LF% THEN INCR L%
             FOR I% = L% TO PF% STEP - 1
              ASTR$(I%) = ASTR$(I%-1)
             NEXT
             ASTR$(PF%) = CH$
             LOCATE YF%,XF%+PF%
             IF PF% < LF% THEN
              IF FT%=5 THEN
               PRINT CHR$(176);
              ELSE
               PRINT CH$;
              END IF
              INCR PF%
             END IF
             'IF FT%=5 THEN CH$=CHR$(13)
           END SELECT
          ELSE
           SELECT CASE CH$
            CASE CHR$(0,75)
             IF PF% > 1 THEN DECR PF%
            CASE CHR$(0,77)
             IF PF% < LF% THEN
              INCR PF%
              IF PF% > L% THEN INCR L%
             END IF
            CASE CHR$(0,83)
             FOR I% = PF% TO L%-1
              ASTR$(I%) = ASTR$(I%+1)
             NEXT
             IF L% >= PF% THEN
              ASTR$(L%) = CHR$(32)
              DECR L%
             END IF
            CASE ELSE
             IF L% < LF% THEN INCR L%
             FOR I% = L% TO PF% STEP - 1
              ASTR$(I%) = ASTR$(I%-1)
             NEXT
             SELECT CASE CH$
              CASE CHR$(0,30)
               ASTR$(PF%) = " "
              CASE CHR$(0,18)
               ASTR$(PF%) = "‚"
              CASE CHR$(0,23)
               ASTR$(PF%) = "¡"
              CASE CHR$(0,24)
               ASTR$(PF%) = "¢"
              CASE CHR$(0,22)
               ASTR$(PF%) = "£"
              CASE CHR$(0,49)
               ASTR$(PF%) = "¤"
              CASE CHR$(0,50)
               ASTR$(PF%) = "¥"
              CASE CHR$(0,36)
               ASTR$(PF%)=CHR$(167)
              CASE ELSE
               ASTR$(PF%) = MID$(CH$,2,1)
              END SELECT
             LOCATE YF%,XF%+PF%
             IF PF% < LF% THEN
              IF FT%=5 THEN
               PRINT CHR$(176);
              ELSE
               'PRINT CH$;
              END IF
              INCR PF%
             END IF
           END SELECT
          END IF
          '             1-CR     2-ESC     3-AUp      5-ADn     7-PgUp     9-PgDn     11-^RightA   13-^LeftA    15-Home    17-End    19-Ins      21-F1      23-F10
          CRS% = INSTR(CHR$(13)+CHR$(27)+CHR$(0,72)+CHR$(0,80)+CHR$(0,73)+CHR$(0,81)+CHR$(0,116)+CHR$(0,115)+CHR$(0,71)+CHR$(0,79)+CHR$(0,82)+CHR$(0,59)+CHR$(0,68),CH$)
          IF CRS% = 1 THEN
           CAD$ = ""
           FOR I% = 1 TO L%
            CAD$=CAD$+ASTR$(I%)
           NEXT
           EXIT LOOP
          ELSE
           IF CRS%=2 THEN EXIT LOOP
           FOR I%=1 TO 23 STEP 2
            IF I%=CRS% THEN EXIT LOOP
           NEXT
          END IF
         LOOP
         COLOR 7,1
        END SUB

        Comment


        • #5
          If you need serious encryption, the message is always Use AES. << disclaimer.

          Now that's out of the way, so I can mention a couple things re. Erik's algo.

          using various functions like If Then Else, *, /, +, -, \, MOD, and loops.
          The problem is they will probably add only linear complexity to both the encoding and difficulty deciphering the code. As Stuart says, as shown the code would be rather easy to decipher with no key.

          The below solution is linearly as easy to encode, But... exponentially more difficult to decode. That is, two times as much encoding gives up to millions or more times difficulty decoding. It uses two rounds of encoding to achieve that end. You could even use 3 or more rounds if wanted, but the basic code is still the same simple algo.
          Code:
          #COMPILE EXE
          #DIM ALL
          
          FUNCTION PBMAIN () AS LONG
              LOCAL i AS LONG
              LOCAL s AS STRING
              s = "Isaac became a hurricane Tuesday that could flood the " + _
                  "coasts of four states with storm surge and heavy rains " + _
                  "on its way to New Orleans, where residents hunkered down " + _
                  "behind levees fortified after Katrina struck seven years ago this week." & _
                  "1234567890-=!@#$%^&*()_+{}|[]\:;'<>?,./~`" & _
                  "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
              MSGBOX s
          
              ' encrypt 1st round
              RANDOMIZE 1.99348e-13!       ' must be the same for 1st round
                                           ' encryption and decryption, and should be a 7-digit SINGLE
              FOR i = 1 TO LEN(s)
                  ASC(s, i) = ASC(s, i) + RND(0,255) ' plus
              NEXT
              MSGBOX REMOVE$(s, $NUL)      ' remove $nul's only for messagebox viewing
              
              ' 2nd round
              RANDOMIZE 1.54517e21!        ' must be the same for 2nd round
                                           ' encryption and decryption, and should be a different SINGLE
              FOR i = 1 TO LEN(s)
                  ASC(s, i) = ASC(s, i) - RND(0,255) ' minus
              NEXT
              MSGBOX REMOVE$(s, $NUL),,"Final Encrypted Bytes"
              
          
              ' Now decrypt using same password SINGLE's but with Reverse Signs
              RANDOMIZE 1.99348e-13!
              FOR i = 1 TO LEN(s)
                  ASC(s, i) = ASC(s, i) - RND(0,255) ' -
              NEXT
              MSGBOX REMOVE$(s, $NUL)
              
              RANDOMIZE 1.54517e21!
              FOR i = 1 TO LEN(s)
                  ASC(s, i) = ASC(s, i) + RND(0,255) ' +
              NEXT
              MSGBOX REMOVE$(s, $NUL)
          END FUNCTION
          Last edited by John Gleason; 31 Aug 2012, 01:36 PM. Reason: changed 6 to 7 (in red per post 11)

          Comment


          • #6
            Admittedly, nothing like as much fun.

            [ >= XP ]

            Code:
            #Compile Exe
            #Dim All
            
            DECLARE FUNCTION RtlEncryptMemory LIB "AdvApi32.dll" _
                Alias "SystemFunction040" (_
                Memory            As Any, _
                ByVal MemorySize  As Dword, _
                ByVal OptionFlags As Dword _
                ) As Long
            
            Declare Function RtlDecryptMemory Lib "AdvApi32.dll" _
                Alias "SystemFunction041" (_
                Memory            As Any, _
                ByVal MemorySize  As Dword, _
                ByVal OptionFlags As Dword _
                ) As Long 
            
            Function PBMain() As Long
            Local s As String * 512
            
              s = "Isaac became a hurricane Tuesday that could flood the " + _
                    "coasts of four states with storm surge and heavy rains " + _
                    "on its way to New Orleans, where residents hunkered down " + _
                    "behind levees fortified after Katrina struck seven years ago this week." & _
                    "1234567890-=!@#$%^&*()_+{}|[]\:;'<>?,./~`" & _
                    "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
                    
              MsgBox s
              
              RtlEncryptMemory( s, SizeOf(s), 0)
            
              MsgBox s
               
              RtlDecryptMemory( s, SizeOf(s), 0)
            
              MsgBox s
              
            End Function

            Comment


            • #7
              John, I have a concern with this snippet.
              Code:
              FOR i = 1 TO LEN(s)
                      ASC(s, i) = ASC(s, i) + RND(0,255) ' plus
                  NEXT
              There is very real possibility that 's' could exceed 255 at which point the program will crash.

              Or is there something I missed.
              There are no atheists in a fox hole or the morning of a math test.
              If my flag offends you, I'll help you pack.

              Comment


              • #8
                Mel,
                Even though Help says "If the stringVar is ANSI, the CharCode must be in the range of 0 to 255", it doesn't crash or even throw and error if you go outside that limit. It seems that ASC() is very forgiving. (Not that you can rely on it being the same in the next version):

                Code:
                #COMPILE EXE
                #DIM ALL
                #DEBUG DISPLAY ON
                #DEBUG ERROR ON
                FUNCTION PBMAIN () AS LONG
                     DIM a AS STRING
                     a = "a"
                     TRY
                         ASC(a,1) = ASC(a,1) + 400
                     CATCH
                         ? "Error: " & STR$(ERR)
                     FINALLY
                        ? a
                        ? STR$(ASC(a,1))
                     END TRY
                END FUNCTION
                --
                [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                PNG Domain Hosting[/URL]

                Comment


                • #9
                  Guess I must have misread something along the way.

                  I was under the impression that 's' was a string, i.e., "s = "The quick brown fox"" and that you were replacing one CHR$ (plain text) with another CHR$ (cipher text) within the string. It's kind of hard having a CHR$(x + 400).
                  There are no atheists in a fox hole or the morning of a math test.
                  If my flag offends you, I'll help you pack.

                  Comment


                  • #10
                    It's kind of hard having a CHR$(x + 400).
                    CHR$ and ASC (and other functions probably) take just the least signif byte of the value or expression, and always have as I recall. Probably they always will, since that wraparound logic seems the most useful.

                    Code:
                    #COMPILE EXE
                    #DIM ALL
                    
                    FUNCTION PBMAIN () AS LONG
                       LOCAL ii AS LONG, lineo AS STRING
                        ii = 1234567680
                        lineo = CHR$(&h31)                    '&h31 is the char "1"
                        ? lineo
                        lineo = CHR$(&h31 + ii)               'always takes just the least signif byte
                        ? lineo
                        lineo = CHR$(&h1234567812345631)      '     "                   "
                        ? lineo
                        lineo = CHR$(&h1234567812345631 + ii) '     "                   "
                        ? lineo
                    
                    END FUNCTION

                    Comment


                    • #11
                      Regarding post #5 above, I said use 6 digits for the singles. Welp, after I did a test using 7 digits, I now have determined using RANDOMIZE with a 7-digit single gives each a unique initial starting position in the sequence, so that should read: should be a 7-digit single. That gives about 750MB rather than 75MB starting positions.

                      Comment


                      • #12
                        How's about Randomize Cvs(Chr$(85,32,1,48)) and Randomize Cvs(Chr$(67,23,45,12)), or whatever, and we now have access to 256^4 entry points. ie the full monty of 2^32 (= 256^4) entry points.

                        Comment


                        • #13
                          That's probably the easiest way to get the whole shootin' match. Just check to be sure your result is a valid SINGLE first, ie. from 8.43*10^-37 to 3.40*10^38 because you might get "Not A Number" or "denormal" results occasionally with that method.

                          Comment


                          • #14
                            Thanks guys

                            I am learning a lot

                            2 questions:

                            1 Would it not be better to encrypt by changing the order of the message - as well?

                            2 Do you think it would be a good idea if PB had an option to allow encryption on source code? Or has it already and I missed it?
                            [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                            Kerry Farmer

                            Comment


                            • #15
                              > Just check to be sure your result is a valid SINGLE first, ie. from 8.43*10^-37 to 3.40*10^38 because you might get "Not A Number" or "denormal" results occasionally with that method.

                              1. Help says "The default seed can be duplicated with the following statement:RANDOMIZE CVS(CHR$(255,255,255,255))"
                              and
                              2. We have already established that CHR$() only recognises the low order byte of a number passed to it.

                              Can you come up with a value for CVS(CHR$(w,x,y,z)) which does not return a valid single?
                              --
                              [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                              PNG Domain Hosting[/URL]

                              Comment


                              • #16
                                Here is John's code where the seeds are not hard wired but random. ( Needs >= XP )

                                Code:
                                #Compile Exe
                                #Dim All
                                
                                Declare Function RtlGenRandom Lib "Advapi32.dll" Alias "SystemFunction036" _
                                  ( ByRef RandomBuffer As Any, ByVal RandomBufferLength As Dword ) As Byte
                                
                                Function PBMain () As Long
                                    Local i As Long
                                    Local s As String
                                    Local strRound1 As String * 4
                                    Local strRound2 As String * 4
                                    
                                    s = "Isaac became a hurricane Tuesday that could flood the " + _
                                        "coasts of four states with storm surge and heavy rains " + _
                                        "on its way to New Orleans, where residents hunkered down " + _
                                        "behind levees fortified after Katrina struck seven years ago this week." & _
                                        "1234567890-=!@#$%^&*()_+{}|[]\:;'<>?,./~`" & _
                                        "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
                                    MsgBox s
                                    
                                    RtlGenRandom(strRound1, 4)
                                    RtlGenRandom(strRound2, 4)
                                
                                    ' encrypt 1st Round
                                    Randomize Cvs(strRound1)
                                    For i = 1 To Len(s)
                                        Asc(s, i) = Asc(s, i) + Rnd(0,255) ' plus
                                    Next
                                    MsgBox Remove$(s, $Nul)      ' remove $Nul's Only For MessageBox viewing
                                    
                                    ' 2nd Round
                                    Randomize Cvs(strRound2)
                                    For i = 1 To Len(s)
                                        Asc(s, i) = Asc(s, i) - Rnd(0,255) ' minus
                                    Next
                                    MsgBox Remove$(s, $Nul),,"Final Encrypted Bytes"
                                    
                                
                                    ' Now decrypt Using same password Single's but With Reverse Signs
                                    Randomize Cvs(strRound1)
                                    For i = 1 To Len(s)
                                        Asc(s, i) = Asc(s, i) - Rnd(0,255) ' -
                                    Next
                                    MsgBox Remove$(s, $Nul)
                                    
                                    Randomize Cvs(strRound2)
                                    For i = 1 To Len(s)
                                        Asc(s, i) = Asc(s, i) + Rnd(0,255) ' +
                                    Next
                                    MsgBox Remove$(s, $Nul)
                                End Function

                                Comment


                                • #17
                                  >Here is John's code where the seeds are not hard wired but random.

                                  IOW, If you encrypt a string, save it somewhere and close the application or send the encrypted string to another application, you can't decrypt it.

                                  I can't think of too many situation where I would only want to encrypt and then decrypt a string during a single run of an application.
                                  --
                                  [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                                  PNG Domain Hosting[/URL]

                                  Comment


                                  • #18
                                    Stuart, I continue here in Programming:

                                    continue

                                    Comment


                                    • #19
                                      Thanks for your comments and ideas.

                                      I like John’s idea of using two or more rounds of encoding (and decoding).

                                      Kerry’s suggestion of changing the order of the message should be used in addition. Manipulating the random numbers using the functions, I mentioned, and others could accomplish that. This would be slightly more complicated because it should be done in such a way, that decoding is still possible. Nevertheless the possible code variations should be numerous.
                                      Last edited by Erik Christensen; 3 Sep 2012, 09:22 AM.

                                      Comment

                                      Working...
                                      X