QB / QB64 Discussion Forum      Other Subforums, Links and Downloads

Respond to this messageReturn to Index
Original Message
  • qbasic 1.1
    • (Login MCalkins)
      Moderator
      Posted Jan 31, 2012 6:57 PM

      It is much, much slower.

      The program is basically the same, with the data types changed, and the loop replaced with RUN. The screen buffer is used to store the passphrase between runs. The rseed array is gone.

      Note: execute CLS in the immediate window before running.

      I lack understanding of QBASIC's pseudo random number generator. With more knowledge, it would probably be possible to reseed it without restarting the program. I'd like to do an assembly version of the decryption algorithm, for fun and for improved efficiency. I could have the qbasic 1.1 version call an assembly routine, providing it with the RND sequence. Or, if I can find a good description of QBASIC's pseudo random number generator, I might try implementing the whole thing in assembly. Maybe after lunch... :-)

      Regards,
      Michael

      'jan 2012, michael calkins
      'my code is public domain
      'algorithm and ciphertext are from lawgin

      DIM seed AS LONG
      DIM i AS INTEGER
      DIM n AS INTEGER
      DIM temp AS INTEGER
      DIM ct(0 TO 9) AS INTEGER 'ciphertext
      DIM pt(0 TO 9) AS INTEGER 'plaintext
      DIM pp(0 TO 6) AS INTEGER 'passphrase

      ct(0) = ASC("O")
      ct(1) = ASC("M")
      ct(2) = ASC("N")
      ct(3) = ASC("A")
      ct(4) = ASC("N")
      ct(5) = ASC("2")
      ct(6) = ASC("L")
      ct(7) = ASC("=")
      ct(8) = ASC("\")
      ct(9) = ASC("6")

      DEF SEG = &HB800
      FOR i = 0 TO 6
       pp(i) = PEEK(&HF00 + i + i)
      NEXT
      IF pp(0) = &H20 THEN
       FOR i = 0 TO 6
        pp(i) = &H30
       NEXT
      END IF

       seed = 0
       FOR n = 0 TO 6
        seed = seed + pp(n) ^ 2
       NEXT
       RANDOMIZE seed

       FOR n = 0 TO 9
        temp = (ct(n) - &H21) XOR (INT(&H40 * RND) + 1)
        SELECT CASE temp
         CASE &H2F TO &H39
         CASE ELSE
          EXIT FOR
        END SELECT
        pt(n) = temp
       NEXT
       IF n = 10 THEN
        FOR n = 0 TO 6
         PRINT CHR$(pp(n));
        NEXT
        PRINT " --> ";
        FOR n = 0 TO 9
         PRINT CHR$(pt(n));
        NEXT
        PRINT "  seed:"; seed
       END IF

       IF pp(6) = &H7A THEN END
       FOR n = 0 TO 6
        SELECT CASE pp(n)
         CASE &H39: pp(n) = &H41: EXIT FOR
         CASE &H5A: pp(n) = &H61: EXIT FOR
         CASE &H7A:
         CASE ELSE: pp(n) = pp(n) + 1: EXIT FOR
        END SELECT
       NEXT
       IF n THEN
        FOR i = 0 TO n - 1
         pp(i) = pp(n)
        NEXT
       END IF
       FOR i = 0 TO 6
        POKE &HF00 + i + i, pp(i)
       NEXT
      RUN
    Login Status
  • You are not logged in
    • Login
      Password
       

      Optional
      Provides additional benefits such as notifications, signatures, and user authentication.


      Create Account
    Your Name
    Message Title
    Message Text
    Options