OpenCores
URL https://opencores.org/ocsvn/csa/csa/trunk

Subversion Repositories csa

[/] [csa/] [trunk/] [sw_sim/] [key_perm.c] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 simon111
/*
2
 * =====================================================================================
3
 *
4
 *       Filename:  key_perm.c
5
 *
6
 *    Description:  this file tests the key_perm function
7
 *
8
 *        Version:  1.0
9
 *        Created:  07/05/2008 07:51:58 AM
10
 *       Revision:  none
11
 *       Compiler:  gcc
12
 *
13
 *         Author:  mengxipeng$gmai.com
14
 *        Company:  mengxipeng
15
 *
16
 * =====================================================================================
17
 */
18
 
19
#include <stdio.h>
20
#include <memory.h>
21
 
22
extern unsigned char key_perm[0x40]; /* defined in csa.c */
23
 
24
unsigned char i_key[8];
25
unsigned char o_key[8];
26
 
27
int main()
28
{
29 13 simon111
        int           i;
30
        int           j;
31
        int           k;
32 10 simon111
        unsigned char p;
33 13 simon111
        int           v;
34
        int           c;
35
        int           b;
36
        /* first read the input key */
37 10 simon111
        memset(i_key,0,sizeof i_key);
38
        for (i=63;i>=0;i--)
39
        {
40
             c=getchar();
41
             printf("%c",c);
42
             if(c=='1')
43
             {
44
                     i_key[i/8]|=(1<<(i%8));
45
             }
46
        }
47
        printf("\n");
48
 
49
        /*  now do the key_perm operatioin */
50
        memset(o_key,0,sizeof o_key);
51
        /* 64 bit perm on kb */
52
        for (j = 0; j < 8; j++)
53
        {
54
                for (k = 0; k < 8; k++)
55
                {
56
                        b=key_perm[j*8+k]-1;
57
                        if((i_key[j] >> (7 - k)) & 1)
58
                        {
59
                                o_key[b/8] |= (1<<(7-(b%8)));
60
                        }
61
                }
62
        }
63
 
64
        /*  output the o_key */
65
        for (i=63;i>=0;i--)
66
        {
67
                if(o_key[i/8]&(1<<(i%8)))
68
                        printf("1");
69
                else
70
                        printf("0");
71
        }
72
        printf("\n");
73
 
74
        return 0;
75
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.