zoukankan      html  css  js  c++  java
  • GF(2^8)生成元

    目的是找出所有GF(2^8)的生成元。

    方法很简单,从2开始遍历,将每个元素都与自身相乘255次,看是否能得到1~255。若能,则是生成元。

    #include<iostream>
    #include<fstream>
    using namespace std;
    unsigned char GFmul(unsigned char a, unsigned char b){
        //GF(2^8) 乘法
        unsigned char result = 0;
        if((b&1) == 1)result = a;
        b >>= 1;
        for(int i = 1; i < 8; i ++){
            if(a > 127){
                a = (a << 1) ^ 0x1b;
            }
            else{
                a <<= 1;
            }
            if((b&1) == 1){
                result ^= a;
            }
            b >>= 1;
        }
        return result;
    }
    int findGenerator(int result[]){
        //找出所有GF(2^8)的生成元
        unsigned char x = 2;        //从2开始查找
        int len = 0;
        do{
            int count[256], i;
            for(i = 0; i < 256; i ++)count[i] = 0;
            count[x] ++;
            unsigned char tmp = x;
            for(i = 2; i < 256; i ++){
                tmp = GFmul(tmp, x);
                count[tmp] ++;
            }
            for(i = 1; i < 256; i ++){
                //查看是否所有的数都有生成,若是,则x为生成元
                if(count[i] != 1)break;
            }
            if(i == 256)result[len ++] = x;
            x ++;
        }while(x != 0);
        return len;
    }
    int main(){
        //单元测试。输出所有的生成元。
        int result[256];
        int len = findGenerator(result);
        ofstream write("Test.txt");
        for(int i = 0; i < len; i ++)write<<result[i]<<endl;
        write.close();
        return 0;
    }
    C++
  • 相关阅读:
    移动端页面滚动性能调优
    外盘期货交易安全吗
    Vuetify的pagination功能踩坑
    oh-my-zsh自定义主题
    SSM整合
    Spring底层学习 1
    Node.js+Express day01
    JS+DOM conclusions
    tables+form+validation+Semantic HTML
    mybatis-利用association和collection实现一对一和一对多
  • 原文地址:https://www.cnblogs.com/7hat/p/3383524.html
Copyright © 2011-2022 走看看