Last active
January 16, 2022 22:29
-
-
Save ryandesign/b34aa04f97c0b7a7ae7f2c560404b668 to your computer and use it in GitHub Desktop.
Program 1 from Micro Adventure No. 9: Dead Ringer in its original AppleSoft BASIC and converted to C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 REM DECODER | |
110 GOSUB 900 | |
120 PRINT "(TYPE 'STOP' TO END)" :PRINT | |
130 PRINT "ENTER MESSAGE:" | |
140 INPUT M$ | |
150 IF M$="STOP" THEN END | |
160 FOR I=1 to LEN(M$) | |
170 A$=M$:SB=I:SE=1:GOSUB 800 | |
180 L$=XC$ | |
190 IF ((L$<"A")+(L$>"Z")) THEN 250 | |
200 KT=KT+1:IF KT>26 THEN KT=1 | |
210 T=ASC(L$):T=T-KT | |
220 IF T< ASC("A") THEN T=T+26 | |
230 PRINT CHR$(T); | |
240 GOTO 260 | |
250 PRINT L$; | |
260 NEXT I | |
270 PRINT:PRINT:GOTO 130 | |
800 XC$=MID$(A$,SB,SE):RETURN | |
900 HOME:RETURN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
To compile this code, run: | |
cc -o decoder decoder.c | |
To run it, run: | |
./decoder | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) { | |
char character, done = 0, kt = 0, *message = NULL; | |
size_t buffer_size = 0, index; | |
ssize_t length = 0; | |
printf("(TYPE 'STOP' TO END)\n\n"); | |
while (!done) { | |
printf("ENTER MESSAGE:\n"); | |
putchar('?'); | |
length = getline(&message, &buffer_size, stdin); | |
if (length == -1 || strncmp(message, "STOP\n", buffer_size) == 0) { | |
done = 1; | |
} else { | |
for (index = 0; index < length; ++index) { | |
character = message[index]; | |
if (character >= 'A' && character <= 'Z') { | |
++kt; | |
if (kt > 26) kt = 1; | |
character -= kt; | |
if (character < 'A') character += 26; | |
} | |
putchar(character); | |
} | |
} | |
putchar('\n'); | |
} | |
if (message) { | |
free(message); | |
message = NULL; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment