Author Topic: I need help with this program, that creates random bytes and can encrypt a file.  (Read 3651 times)

0 Members and 1 Guest are viewing this topic.

Offline Dragoncat

  • Newbie
  • Posts: 10
    • View Profile
DECLARE SUB Rndmiz ()
DECLARE FUNCTION Grand! ()
DIM SHARED Pad1$(15), Pad2$(15), ToByte(63), ToB64(255), Mods(12)
COMMON SHARED L0, L1, L2, L3, ToB64(), L5, ToByte(), L7, Mods(), L9, L10$
COMMON SHARED L11$, L13$, I14, I15, I17, L20, Pad1$(), Pad2$(), L26$, L28$, I29
COMMON SHARED I34, L35, L36, L37$, I38, I39, L40!, I42, Modder2, L44, L45
COMMON SHARED L46, Modder, I50, L51$, L54
L0 = 0
L3 = 255
L1 = 1
L5 = 63
L7 = 12
Modder = 64
Modder2 = 256
110 RANDOMIZE TIMER
120 FOR L2 = L0 TO L3 STEP L1
    130 ToB64(INT(L2)) = -1
140 NEXT
150 FOR L2 = L0 TO L5 STEP L1
    160 READ ToByte(INT(L2))
    170 ToB64(ToByte(INT(L2))) = INT(L2)
180 NEXT
190 FOR L2 = L0 TO L7 STEP L1
    200 READ Mods(INT(L2))
210 NEXT
220 L9 = L0
222 SHELL "dir *.* /w /p"
390 INPUT "enter file to encrypt/decrypt"; L26$
400 INPUT "enter name of output file"; L28$
INPUT "enter seed (password)"; L13$
I14 = LEN(L13$)
IF I15 <= 15 THEN GOTO set2max
L13$ = LEFT$(L13$, 15)
set2max: I17 = 15
FOR L2 = L0 TO 15 STEP L1
    PRINT "("; L2; ") ";
    Pad1$(INT(L2)) = LEFT$(L13$, 1)
    L13$ = RIGHT$(L13$, I17)
    Pad2$(INT(L2)) = Pad1$(INT(L2))
    I17 = I17 - 1
NEXT
430 OPEN L26$ FOR BINARY AS #1
440 OPEN L28$ FOR BINARY AS #2
450 I34 = LOF(1)
REM 460 L35 =  'L35 apparently is not being used...
470 L36 = I34
480 GOTO 600
490 CALL Rndmiz
495 L40! = Grand!
peel& = 32
IF I34 < 32 THEN peel& = I34
510 L37$ = STRING$(peel&, 32)
520 GET #1, I39, L37$
strlen = LEN(L37$)
FOR sloc = 1 TO strlen
    CALL Rndmiz
    L40! = Grand!
    530 IR12 = INT(L40! / 256) '( # Top half of long integer # )
    540 IR14 = (INT(L40! * 256)) MOD 256
    IF sloc <= LEN(L37$) THEN
        bite$ = MID$(L37$, sloc, 1)
        550 I42 = ASC(bite$) XOR IR14
        560 L37$ = CHR$(I42 MOD Modder2)
    END IF
NEXT sloc
570 PUT #2, I39, L37$
580 IF I29 <> 1 THEN GOTO 600
590 PRINT L37$;
600 I39 = I39 + 1
610 I38 = I38 + 1
620 IF I39 <= L36 THEN GOTO 490
630 CLOSE #2
640 CLOSE #1
650 SYSTEM
870 DATA 32,33,34,35,36,37,38,39
880 DATA 40,41,42,43,44,45,46,47
890 DATA 48,49,50,51,52,53,54,55
900 DATA 56,57,58,59,60,61,62,63
910 DATA 64,65,66,67,68,69,70,71
920 DATA 72,73,74,75,76,77,78,79
930 DATA 80,81,82,83,84,85,86,87
940 DATA 88,89,90,91,92,93,94,95
950 DATA 2,3,5,7,11,13,17,19,23,27,33,37,43
960 END

FUNCTION Grand!
    L40! = 0!
    L54 = .015625
    FOR L2 = 13 TO 15 STEP L1
        L40! = (ASC((Pad1$(INT(L2)))) - 32) * L54 + L40!
        L54 = L54 / 64
    NEXT
    Grand! = L40!
END FUNCTION

SUB Rndmiz
    L45 = Mods(INT(L9))
    FOR L46 = 0 TO 3 STEP 1
        FOR L2 = 0 TO 15 STEP 1
            IF (L2 MOD 2) <> 0 THEN GOTO skp1
            L45 = (ASC((Pad1$(INT(L2)))) + -32) + L45
            skp1: IF (L2 MOD 2) <> 1 THEN GOTO skp2
            L45 = (-(ASC((Pad1$(INT(L2)))) - 95)) + L45
            skp2: IF L2 <= L0 THEN GOTO bland01
            Pad1$(INT(L2 - 1)) = Pad1$(INT(L2))
        bland01: NEXT
        I50 = L45 MOD Modder
        L51$ = CHR$(ToByte(I50))
        L9 = (L9 + L1) MOD 13
    NEXT
END SUB

this does not seem to work in the latest version of  QB64 I get the message Invalid name on line 96 what is wrong??
There Removed (45 pad$...) on line 96 and the program works FINE!! feel free to copy it and try it out!! Ill be making som minor improvements to it eventually, like having it give you a list of available files, thus letting you more easily select a file etc...
« Last Edit: May 08, 2019, 12:13:41 pm by Dragoncat »

Marked as best answer by Dragoncat on May 08, 2019, 07:23:07 am

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Code: QB64: [Select]
  1. SUB Rndmiz (45 pad1$)  ' <<<<<<<<<<<< look at this line???? (96)
  2.  

Earlier in your program you Call Rndmiz without any arguments and it will compile if I remove (45 pad1$).

BTW code tags (to put your code in a code window) are here:
 
Code tag.PNG
« Last Edit: May 08, 2019, 11:22:06 am by bplus »

Offline Dragoncat

  • Newbie
  • Posts: 10
    • View Profile
Thanks a lot !!! It must have added that sometime later as some sort of a glitch that happened, program works fine now!!, give it a try..It does need the added functionality of letter the user look for and browse files and choose a file to encrypt / decrypt etc... but it is a fine start! thanks for fixing the problem , I would have never guessed that it was an argument thing like that, I wonder if the argument was needed for the program to work correctly or not, I will have to review my programs inner workings, flow chart it have tests done for randomness etc... lot of work still needs to be done, but thanks!!!, thanks a lot!!