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
|
dd if=/dev/urandom count=1 | md5sum - > $BASE/salt
|
||||||
fi
|
fi
|
||||||
clear
|
clear
|
||||||
|
printf '\017'
|
||||||
read salt < $BASE/salt
|
read salt < $BASE/salt
|
||||||
|
|
||||||
esc () {
|
esc () {
|
||||||
|
@ -64,28 +65,52 @@ elif ! [ -d $BASE/$hash ]; then
|
||||||
fini
|
fini
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
read -r name < $BASE/$hash/.name
|
read -r name < $BASE/$hash/.name
|
||||||
printf "%s answer: " "$name"
|
|
||||||
read -r answer
|
|
||||||
echo
|
|
||||||
|
|
||||||
match=$(awk -v ans="$answer" '(substr($0, length($1)+2) == ans) { print substr(FILENAME, 6, length(FILENAME)-17) " " $1; }' /opt/*/answers.txt)
|
printf 'Welcome back, [34m%s[0m.\n' "$name"
|
||||||
if [ -z "$match" ]; then
|
|
||||||
echo "That is not a correct answer."
|
|
||||||
fini
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat=${match% *}
|
while true; do
|
||||||
points=${match#* }
|
printf "[32mp2>[0m "
|
||||||
fn=$BASE/$hash/$cat.$points
|
read -r answer
|
||||||
if [ -f $fn ]; then
|
|
||||||
|
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. Type "[34mhelp[0m" for help.'
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat=${match% *}
|
||||||
|
points=${match#* }
|
||||||
|
fn=$BASE/$hash/$cat.$points
|
||||||
|
if [ -f $fn ]; then
|
||||||
echo "You've already received points for this answer."
|
echo "You've already received points for this answer."
|
||||||
else
|
else
|
||||||
> $fn
|
> $fn
|
||||||
echo "You get $points more points in the $cat category."
|
echo "You get $points more points in the $cat category."
|
||||||
# run puzzles.cgi
|
# run puzzles.cgi
|
||||||
# update scoreboard
|
# update scoreboard
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
fini
|
|
||||||
|
|
||||||
|
|
|
@ -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