小编Pas*_*sor的帖子

Shamir秘密共享的Java实现

我尝试用Java实现Shamir的秘密共享,但我遇到了一些问题.

当我把K> 10时,秘密就不再重建了.谁能帮我?这就是我所做的.有什么问题?

最初我选择N和K,接下来我有系数的产生,股票的创建,最后是重建.

import java.math.BigInteger;
import java.util.Random;


public class Main {
    public static void main(String[] args){

        //INIT
        int N = 55;
        int K = 11;

        BigInteger secret = new BigInteger("123");
        modLength = secret.bitLength() + 1;
        BigInteger primeNum = genPrime();
        BigInteger[] coeff = new BigInteger[K-1];
        BigInteger[] partecipants = new BigInteger[K];
        for (int i=0;i<K;i++)
            partecipants[i] = new BigInteger(Integer.toString(i+1));
        System.out.println("Prime Number: "+primeNum);
        for (int i=0;i<K-1;i++){
            coeff[i] = randomZp(primeNum);
            System.out.println("a"+(i+1)+": "+coeff[i]);
        }

        //SHARES
        BigInteger[] shares = new BigInteger[N];
        for(int i=0;i<N;i++){
            BigInteger toAdd= secret; …
Run Code Online (Sandbox Code Playgroud)

java cryptography shared-secret

5
推荐指数
2
解决办法
9668
查看次数

C中的指针和链表

我在C中开始学习指针和链表,但我有一个问题:

struct pointer
{
       int id;
       struct pointer *next;
};

int pop(struct pointer *head, struct pointer *tail);

main()
{
    struct pointer *head = NULL;
    head = (struct pointer*)malloc(sizeof(struct pointer));
    head->id=1;
    struct pointer *tail = head;
    tail->next=NULL;
    pop(head,tail);
    if (head==NULL) printf ("In main, head is NULL");
    else printf ("In main, head is NOT NULL");
}    

int pop(struct pointer *head, struct pointer *tail)
{
    int toReturn;
    struct pointer *toFree;
    if (head!=NULL)
    {
       toReturn = head->id;
       toFree = head;
       head = head->next;
       free(toFree); …
Run Code Online (Sandbox Code Playgroud)

c pointers singly-linked-list

3
推荐指数
1
解决办法
211
查看次数