mirror of https://github.com/dirtbags/moth.git
Console work + modem.c
This commit is contained in:
parent
57cb1a4cdc
commit
fb03774655
|
@ -8,6 +8,7 @@ if ! [ -f $BASE/salt ]; then
|
|||
dd if=/dev/urandom count=1 | md5sum - > $BASE/salt
|
||||
fi
|
||||
clear
|
||||
printf '\017'
|
||||
read salt < $BASE/salt
|
||||
|
||||
esc () {
|
||||
|
@ -64,15 +65,40 @@ elif ! [ -d $BASE/$hash ]; then
|
|||
fini
|
||||
fi
|
||||
|
||||
clear
|
||||
|
||||
read -r name < $BASE/$hash/.name
|
||||
printf "%s answer: " "$name"
|
||||
|
||||
printf 'Welcome back, [34m%s[0m.\n' "$name"
|
||||
|
||||
while true; do
|
||||
printf "[32mp2>[0m "
|
||||
read -r answer
|
||||
echo
|
||||
|
||||
case "$answer" in
|
||||
\?|help)
|
||||
cat <<EOD
|
||||
[32m Help
|
||||
----------------------------------------------------------[0m
|
||||
|
||||
Type "[34mquit[0m" to leave the p2 shell.
|
||||
|
||||
Any other string is checked as an answer. If the answer
|
||||
is correct, you are awarded points and the scoreboard will
|
||||
update within 10 seconds. Check the puzzles overview to
|
||||
see if your answer unlocked a new puzzle.
|
||||
EOD
|
||||
continue
|
||||
;;
|
||||
quit)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
match=$(awk -v ans="$answer" '(substr($0, length($1)+2) == ans) { print substr(FILENAME, 6, length(FILENAME)-17) " " $1; }' /opt/*/answers.txt)
|
||||
if [ -z "$match" ]; then
|
||||
echo "That is not a correct answer."
|
||||
fini
|
||||
echo 'That is not a correct answer. Type "[34mhelp[0m" for help.'
|
||||
continue
|
||||
fi
|
||||
|
||||
cat=${match% *}
|
||||
|
@ -86,6 +112,5 @@ else
|
|||
# run puzzles.cgi
|
||||
# update scoreboard
|
||||
fi
|
||||
|
||||
fini
|
||||
done
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
modem:
|
|
@ -0,0 +1,60 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NOISE_PROB 300
|
||||
#define NOISE_BITS 16
|
||||
|
||||
int badbits = 0;
|
||||
|
||||
char
|
||||
line_noise(char c)
|
||||
{
|
||||
int i = 7;
|
||||
|
||||
while (badbits && (i >= 0)) {
|
||||
c = c ^ ((rand() % 2) << i);
|
||||
badbits -= 1;
|
||||
i -= 1;
|
||||
}
|
||||
|
||||
if (rand() % NOISE_PROB == 0) {
|
||||
badbits = rand() % NOISE_BITS;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char c;
|
||||
ssize_t ret;
|
||||
int baud = 0;
|
||||
useconds_t usec;
|
||||
|
||||
if (argv[1]) {
|
||||
baud = atoi(argv[1]);
|
||||
}
|
||||
if (! baud) {
|
||||
baud = 1200;
|
||||
}
|
||||
|
||||
srandom(getpid());
|
||||
|
||||
/*
|
||||
N81 uses 1 stop bit, and 1 parity bit. That works out to
|
||||
exactly 10 bits per byte.
|
||||
*/
|
||||
usec = 10000000 / baud;
|
||||
|
||||
while (1) {
|
||||
ret = read(0, &c, 1);
|
||||
if (ret != 1) {
|
||||
break;
|
||||
}
|
||||
c = line_noise(c);
|
||||
write(1, &c, 1);
|
||||
usleep(usec);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue