Author Topic: Password Seeded Bit Encryption  (Read 3106 times)

0 Members and 1 Guest are viewing this topic.

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Password Seeded Bit Encryption
« on: March 01, 2020, 03:35:04 pm »
Here is a program for encrypting and decrypting files. I did not write it, and I'm sure the NSA could break it in two femtoseconds, but I have used it and it seems to work. I am thinking of adding the ability to do batch encrypt/decrypt on my list of things I want to do.

Anyway, I was thinking you all might want to add this to the Samples Gallery or Programs sections. Thanks, Mike

Code: QB64: [Select]
  1. ['''
  2. ' P_S_B_E (Password_Seeded_Bit_Encryption), version 1.1
  3. '
  4. ' (C)opyright 2004, Pure QB Innovations
  5. '
  6. '
  7. ' Email any questions, comments, or beta results to...
  8. ' ESmemberNEMESIS@aol.com
  9. '
  10. ' Visit the Pure QB Innovations web site at...
  11. ' http://members.aol.com/esmembernemesis/index.htm
  12. '
  13. ' THIS PROGRAM MAY BE DISTRIBUTED FREELY AS PUBLIC DOMAIN SOFTWARE
  14. ' AS LONG AS ANY PART OF THIS FILE IS NOT ALTERED IN ANY WAY.
  15. ' IF YOU DO WISH TO USE THESE ROUTINES IN YOUR OWN PROGRAMS
  16. ' THEN PLEASE GIVE CREDIT TO THE AUTHOR... Mario LaRosa.
  17. '
  18. '''
  19. '
  20. ON ERROR GOTO Event
  21. '
  22. DEFINT A-Z
  23. '
  24. '
  25. GOSUB Title
  26. GOSUB Menu
  27. GOSUB File
  28. GOSUB Pass
  29. GOSUB Plant
  30. GOSUB Algorithm
  31. GOSUB Status
  32. '
  33. '
  34. Title:
  35. COLOR 8: LOCATE 25, 1: PRINT "( )opyright 2004,";
  36. COLOR 7: LOCATE 25, 2: PRINT "C";
  37. COLOR 4: LOCATE 25, 19: PRINT "Pure";
  38. COLOR 2: LOCATE 25, 24: PRINT "QB";
  39. COLOR 1: LOCATE 25, 27: PRINT "Innovations";
  40. COLOR 8: LOCATE 1, 25: PRINT "Password_Seeded_Bit_Encryption"
  41. COLOR 7: LOCATE 1, 25: PRINT "P"
  42. LOCATE 1, 34: PRINT "S"
  43. LOCATE 1, 41: PRINT "B"
  44. LOCATE 1, 45: PRINT "E"
  45. '
  46. Menu:
  47. PRINT "Please choose an option..."
  48. PRINT " [";: COLOR 7: PRINT "D";: COLOR 8: PRINT "]ecrypt file"
  49. PRINT " [";: COLOR 7: PRINT "E";: COLOR 8: PRINT "]ncrypt file"
  50. PRINT " [";: COLOR 7: PRINT "Q";: COLOR 8: PRINT "]uit PSBE"
  51.     K$ = INKEY$
  52.     SELECT CASE UCASE$(K$)
  53.         CASE "E"
  54.             Choice$ = "encrypt"
  55.             EXIT DO
  56.         CASE "D"
  57.             Choice$ = "decrypt"
  58.             EXIT DO
  59.         CASE "Q"
  60.             COLOR 7
  61.             SYSTEM
  62.     END SELECT
  63. '
  64. File:
  65. GOSUB Title
  66. PRINT: PRINT: PRINT "Enter the name (including the source path),"
  67. PRINT "of the file you wish to "; Choice$; "..."
  68. COLOR 7: PRINT: LINE INPUT " "; File$
  69. FileNum = FREEFILE
  70. OPEN File$ FOR BINARY AS FileNum
  71. LenFile& = LOF(FileNum)
  72. IF LenFile& = 0 THEN CLOSE FileNum: KILL File$: ERROR 53
  73. '
  74. Pass:
  75. PRINT: PRINT "Enter password to "; Choice$; " this file..."
  76. PRINT: LINE INPUT " "; Password$
  77. LenPassword = LEN(Password$)
  78. IF LenPassword < 1 THEN
  79.     COLOR 4
  80.     PRINT: PRINT "Password not legal."
  81.     SLEEP 2
  82.     RUN
  83. '
  84. Plant:
  85. seed& = &H8000
  86. RANDOMIZE LenPassword
  87. FOR x = 1 TO LenPassword
  88.     r = INT(RND(1) * LenPassword + 1)
  89.     seed& = seed& + ASC(MID$(Password$, r, 1)) + (&H100 * (x - 1))
  90. RANDOMIZE seed&
  91. '
  92. Algorithm:
  93. COLOR 4: PRINT: PRINT "Are you sure?"
  94. COLOR 8: PRINT: PRINT " [ ]o or [ ]es";
  95. COLOR 15: LOCATE 15, 3: PRINT "N"
  96. LOCATE 15, 11: PRINT "Y"
  97.     K$ = INKEY$
  98.     SELECT CASE UCASE$(K$)
  99.         CASE "Y"
  100.             COLOR 2: PRINT: PRINT "..."; Choice$; "ing..."
  101.             EXIT DO
  102.         CASE "N"
  103.             RUN
  104.     END SELECT
  105. DIM b AS STRING * 1
  106. SELECT CASE Choice$
  107.     CASE "encrypt"
  108.         FOR i& = 1 TO LenFile&
  109.             GET FileNum, i&, b
  110.             r = INT(RND(1) * LenPassword + 1)
  111.             f = ASC(MID$(Password$, r, 1))
  112.             s = ASC(b)
  113.             n = (f + s) AND 255
  114.             b = CHR$(n)
  115.             PUT FileNum, i&, b
  116.         NEXT
  117.     CASE "decrypt"
  118.         FOR i& = 1 TO LenFile&
  119.             GET FileNum, i&, b
  120.             r = INT(RND(1) * LenPassword + 1)
  121.             f = ASC(MID$(Password$, r, 1))
  122.             s = ASC(b)
  123.             n = (s - f) AND 255
  124.             b = CHR$(n)
  125.             PUT FileNum, i&, b
  126.         NEXT
  127. CLOSE FileNum
  128. '
  129. Status:
  130. PRINT: PRINT "File has been "; Choice$; "ed."
  131. '
  132. Event:
  133. COLOR 4: PRINT: PRINT "File not found."
  134. '
  135.  
  136. ]

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Password Seeded Bit Encryption
« Reply #1 on: March 03, 2020, 01:30:09 pm »
It is preferable to put a post with Program Code into the Programs Section, rather than QB64 Discussion.  It is likely to get forgotten here.  This for futre reference.