QB / QB64 Discussion Forum      Other Subforums, Links and Downloads

Respond to this messageReturn to Index
Original Message
  • qbasic 1.1
    • (Login MCalkins)
      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... :-)


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

      DIM seed AS LONG
      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)
      IF pp(0) = &H20 THEN
       FOR i = 0 TO 6
        pp(i) = &H30
      END IF

       seed = 0
       FOR n = 0 TO 6
        seed = seed + pp(n) ^ 2
       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
       IF n = 10 THEN
        FOR n = 0 TO 6
         PRINT CHR$(pp(n));
        PRINT " --> ";
        FOR n = 0 TO 9
         PRINT CHR$(pt(n));
        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
       IF n THEN
        FOR i = 0 TO n - 1
         pp(i) = pp(n)
       END IF
       FOR i = 0 TO 6
        POKE &HF00 + i + i, pp(i)
    Login Status
  • You are not logged in
    • Login

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

      Create Account
    Your Name
    Message Title
    Message Text