Download code
From LiteratePrograms
Back to Ciphersaber_(QBASIC)
Download for Windows: single file, zip
Download for UNIX: single file, zip, tar.gz, tar.bz2
csabre.bas
1 REM Copyright (c) 2009 the authors listed at the following URL, and/or 2 REM the authors of referenced articles or incorporated external code: 3 REM http://en.literateprograms.org/Ciphersaber_(QBASIC)?action=history&offset=20060829081155 4 REM 5 REM Permission is hereby granted, free of charge, to any person obtaining 6 REM a copy of this software and associated documentation files (the 7 REM "Software"), to deal in the Software without restriction, including 8 REM without limitation the rights to use, copy, modify, merge, publish, 9 REM distribute, sublicense, and/or sell copies of the Software, and to 10 REM permit persons to whom the Software is furnished to do so, subject to 11 REM the following conditions: 12 REM 13 REM The above copyright notice and this permission notice shall be 14 REM included in all copies or substantial portions of the Software. 15 REM 16 REM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 REM EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 REM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 REM IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 REM CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 REM TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 REM SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 REM 24 REM Retrieved from: http://en.literateprograms.org/Ciphersaber_(QBASIC)?oldid=7512 25 26 DIM fin$, f1%, fout$, f2%, ky$, q$, i%, j%, j&, s%(255) 27 RANDOMIZE TIMER 28 29 INPUT "Input File (+Encode, -Decode), Output File, Key: ", fin$, fout$,ky$ 30 LET f1% = FREEFILE 31 OPEN MID$(fin$, 2) FOR BINARY AS #f1% 32 LET f2% = FREEFILE 33 OPEN fout$ FOR BINARY AS #f2% 34 35 LET q$ = CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) + CHR$(RND * 256) 36 IF LEFT$(fin$, 1) = "-" THEN GET #f1%, , q$ ELSE PUT #f2%, , q$ 37 LET ky$ = ky$ + q$ 38 39 FOR j% = 0 TO 255 40 LET s%(j%) = j% 41 NEXT 42 FOR i% = 0 TO 255 43 LET j% = (j% + s%(i%) + ASC(MID$(ky$, i% MOD LEN(ky$) + 1, 1))) MOD 256 44 SWAP s%(j%), s%(i%) 45 NEXT 46 47 LET ky$ = " " 48 FOR j& = 1 TO LOF(f1%) + (LEFT$(fin$, 1) = "-") * 10 49 LET i% = (i% + s%(j& MOD 256)) MOD 256 50 SWAP s%(i%), s%(j& MOD 256) 51 GET #f1%, , ky$ 52 LET ky$ = CHR$(ASC(ky$) XOR s%((s%(j& MOD 256) + s%(i%)) MOD 256)) 53 PUT #f2%, , ky$ 54 NEXT 55 56 CLOSE #f1%, f2% 57 SYSTEM 58 59
