~ubuntu-branches/ubuntu/wily/gargoyle-free/wily-proposed

« back to all changes in this revision

Viewing changes to terps/magnetic/Generic/passwd.c

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Beucler
  • Date: 2009-09-11 20:09:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090911200943-idgzoyupq6650zpn
Tags: upstream-2009-08-25
ImportĀ upstreamĀ versionĀ 2009-08-25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <ctype.h>
 
5
#include <limits.h>
 
6
 
 
7
#if UCHAR_MAX==0xff
 
8
typedef unsigned char type8;
 
9
#else
 
10
#error "Can't find an 8-bit integer type"
 
11
#endif
 
12
 
 
13
#if INT_MAX==0x7fffffff
 
14
typedef unsigned int type32;
 
15
#elif LONG_MAX==0x7fffffff
 
16
typedef unsigned long type32;
 
17
#else
 
18
#error "Can't find a 32-bit integer type"
 
19
#endif
 
20
 
 
21
type8 obfuscate(type8 c) {
 
22
        static type8 state;
 
23
        type8          i;
 
24
 
 
25
        if (!c) state=0;
 
26
        else {
 
27
                state^=c;
 
28
                for (i=0;i<13;i++) {
 
29
                        if ((state & 1) ^ ((state>>1) & 1)) state|=0x80;
 
30
                        else state&=0x7f;
 
31
                        state>>=1;
 
32
                }
 
33
        }
 
34
        return state;
 
35
}
 
36
 
 
37
int main(int argc, char **argv) {
 
38
 
 
39
        type8 tmp,name[128],result[128],pad[]="MAGNETICSCR";
 
40
        type32 i,j;
 
41
 
 
42
        if (argc!=2) {
 
43
                printf("Usage: %s string\n",argv[0]);
 
44
                exit(1);
 
45
        }
 
46
 
 
47
        for (i=j=0;i<strlen(argv[1]);i++) {
 
48
                if (argv[1][i]!=0x20) name[j++]=toupper(argv[1][i]);
 
49
        }
 
50
        name[j]=0;
 
51
 
 
52
        tmp=name[strlen(name)-1];
 
53
        if ((tmp=='#') || (tmp==']')) name[strlen(name)-1]=0;
 
54
 
 
55
        if (strlen(name)<12) {
 
56
                for (i=strlen(name),j=0;i<12;i++,j++) name[i]=pad[j];
 
57
                name[i]=0;
 
58
        }
 
59
 
 
60
        obfuscate(0);
 
61
        i=j=0;
 
62
        while (name[i]) {
 
63
                tmp=obfuscate(name[i++]);
 
64
                if (name[i]) tmp+=obfuscate(name[i++]);
 
65
                tmp&=0x1f;
 
66
                if (tmp<26) tmp+='A';
 
67
                else tmp+=0x16;
 
68
                result[j++]=tmp;
 
69
        }
 
70
        result[j]=0;
 
71
        printf("The password for \"%s\" is: %s\n",argv[1],result);
 
72
        return 0;
 
73
}