DOOM password gen for SEGA Saturn
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

169 lines
3.7 KiB

/* saturn doom password gen */
#include <stdio.h>
#define MAX_BULLETS 400
#define MAX_SHELLS 100
#define MAX_ROCKETS 100
#define MAX_CELLS 600
#define MAX_HEALTH 200
#define MAX_ARMOR 200
/* where we'll store out generated password */
char password[10];
/* our look-up-table for password characters */
const char* pwlut = "BCDFGHJKLMNPQRSTVWXYZ0123456789!";
int
encode_value(int value, int maxvalue)
{
int bit;
if (value < 0)
value = 0;
if (value > maxvalue)
value = maxvalue;
/* we shift our value by 3 bits... this is odd */
value = value << 3;
bit = value / maxvalue;
/* shift by one if we cannot cleanly divide */
if (value % maxvalue != 0)
bit += 1;
return bit;
}
int
main(int args, char *argc)
{
int i, bit;
int nextmap;
int gameskill;
int itemquery;
/* clear */
for (i = 0; i < 10; i++)
password[i] = 0;
printf("Level? (1-59):\n");
scanf("%d", &nextmap);
if (nextmap < 1)
nextmap = 1;
if (nextmap > 59)
nextmap = 59;
printf("Skill? (0-3):\n");
scanf("%d", &gameskill);
if (gameskill < 0)
gameskill = 0;
if (gameskill > 3)
gameskill = 3;
/* we need to cache both values independently, because we split level
* and skill across 2 bytes */
password[0] = (nextmap & 62) >> 1;
password[1] = ((nextmap & 1) << 4) | ((gameskill & 3) << 2);
printf("Item: Backpack? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[1] |= 2;
/* weapons */
printf("Item: Chainsaw? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[1] |= 1;
printf("Item: BFG9000? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[2] |= 16;
printf("Item: Plasma? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[2] |= 8;
printf("Item: RPG? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[2] |= 4;
printf("Item: Chaingun? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[2] |= 2;
printf("Item: Double barrel shotgun? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[2] |= 1;
printf("Item: Shotgun? 0 = False, 1 = True:\n");
scanf("%d", &itemquery);
if (itemquery == 1)
password[3] |= 16;
printf("Ammo: Clip? 0 = Min, 400 = Max:\n");
scanf("%d", &itemquery);
bit = encode_value(itemquery, MAX_BULLETS);
password[3] |= (bit & 15);
printf("Ammo: Shell? 0 = Min, 100 = Max:\n");
scanf("%d", &itemquery);
bit = encode_value(itemquery, MAX_SHELLS);
password[4] |= (bit & 15) << 1;
printf("Ammo: Cell? 0 = Min, 600 = Max:\n");
scanf("%d", &itemquery);
bit = encode_value(itemquery, MAX_CELLS);
password[4] |= (bit & 8) >> 3;
password[5] |= (bit & 7) << 2;
printf("Ammo: Rockets? 0 = Min, 100 = Max:\n");
scanf("%d", &itemquery);
bit = encode_value(itemquery, MAX_ROCKETS);
password[5] |= (bit & 12) >> 2;
password[6] |= (bit & 3) << 3;
printf("Health? 0 = Min, 200 = Max:\n");
scanf("%d", &itemquery);
bit = encode_value(itemquery, MAX_HEALTH);
password[6] |= (bit & 14) >> 1;
password[7] |= (bit & 1) << 4;
printf("Armor? 0 = Min, 200 = Max:\n");
scanf("%d", &itemquery);
bit = encode_value(itemquery, MAX_ARMOR);
password[7] |= (bit & 15);
printf("Armor Type? 0 = None, 1 = Green, 2 = Blue:\n");
scanf("%d", &itemquery);
if (itemquery < 0)
itemquery = 0;
if (itemquery > 2)
itemquery = 2;
password[8] |= itemquery;
/* generate our decryption value */
for (i = 0; i < 9; i++)
password[9] ^= password[i];
/* encrypt our password using the calculated XOR value */
for (i = 0; i < 9; i++)
password[i] ^= password[9];
/* print it out to screen */
printf("Your password: ");
for (i = 0; i < 10; i++)
printf("%c", pwlut[password[i]]);
printf("\n");
return 1;
}