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

Subversion Repositories csa

[/] [csa/] [trunk/] [sw_sim/] [key_perm.c] - Diff between revs 13 and 24

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 13 Rev 24
/*
/*
 * =====================================================================================
 * =====================================================================================
 *
 *
 *       Filename:  key_perm.c
 *       Filename:  key_perm.c
 *
 *
 *    Description:  this file tests the key_perm function
 *    Description:  this file tests the key_perm function
 *
 *
 *        Version:  1.0
 *        Version:  1.0
 *        Created:  07/05/2008 07:51:58 AM
 *        Created:  07/05/2008 07:51:58 AM
 *       Revision:  none
 *       Revision:  none
 *       Compiler:  gcc
 *       Compiler:  gcc
 *
 *
 *         Author:  mengxipeng$gmai.com
 *         Author:  mengxipeng$gmai.com
 *        Company:  mengxipeng
 *        Company:  mengxipeng
 *
 *
 * =====================================================================================
 * =====================================================================================
 */
 */
 
 
#include <stdio.h>
#include <stdio.h>
#include <memory.h>
#include <memory.h>
 
 
extern unsigned char key_perm[0x40]; /* defined in csa.c */
extern unsigned char key_perm[0x40]; /* defined in csa.c */
 
 
unsigned char i_key[8];
unsigned char i_key[8];
unsigned char o_key[8];
unsigned char o_key[8];
 
 
int main()
int main()
{
{
        int           i;
        int           i;
        int           j;
        int           j;
        int           k;
        int           k;
        unsigned char p;
        unsigned char p;
        int           v;
        int           v;
        int           c;
        int           c;
        int           b;
        int           b;
        /* first read the input key */
        /* first read the input key */
        memset(i_key,0,sizeof i_key);
        memset(i_key,0,sizeof i_key);
        for (i=63;i>=0;i--)
        for (i=63;i>=0;i--)
        {
        {
             c=getchar();
             c=getchar();
             printf("%c",c);
             printf("%c",c);
             if(c=='1')
             if(c=='1')
             {
             {
                     i_key[i/8]|=(1<<(i%8));
                     i_key[i/8]|=(1<<(i%8));
             }
             }
        }
        }
        printf("\n");
        printf("\n");
 
 
        /*  now do the key_perm operatioin */
        /*  now do the key_perm operatioin */
        memset(o_key,0,sizeof o_key);
        memset(o_key,0,sizeof o_key);
        /* 64 bit perm on kb */
        /* 64 bit perm on kb */
        for (j = 0; j < 8; j++)
        for (j = 0; j < 8; j++)
        {
        {
                for (k = 0; k < 8; k++)
                for (k = 0; k < 8; k++)
                {
                {
                        b=key_perm[j*8+k]-1;
                        b=key_perm[j*8+k]-1;
                        if((i_key[j] >> (7 - k)) & 1)
                        if((i_key[j] >> (7 - k)) & 1)
                        {
                        {
                                o_key[b/8] |= (1<<(7-(b%8)));
                                o_key[b/8] |= (1<<(7-(b%8)));
                        }
                        }
                }
                }
        }
        }
 
 
        /*  output the o_key */
        /*  output the o_key */
        for (i=63;i>=0;i--)
        for (i=63;i>=0;i--)
        {
        {
                if(o_key[i/8]&(1<<(i%8)))
                if(o_key[i/8]&(1<<(i%8)))
                        printf("1");
                        printf("1");
                else
                else
                        printf("0");
                        printf("0");
        }
        }
        printf("\n");
        printf("\n");
 
 
        return 0;
        return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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