1

I have the following information:

  • p: 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
  • q: 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
  • e: 65537
  • c: 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034

And here's my code:

import java.math.BigInteger;
import java.security.SecureRandom;

public class RSA
{
    private final static BigInteger one = new BigInteger("1");
    private final static SecureRandom random = new SecureRandom();

    // prime numbers
    private BigInteger p;
    private BigInteger q;

    // modulus
    private static BigInteger n;

    // totient
    private static BigInteger t;

    // public key
    private static BigInteger e;

    // private key
    private static BigInteger d;

    private static String cipherText = "83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034";

    public RSA()
    {
        p = new BigInteger("9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483");
        q = new BigInteger("11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407");

        n = p.multiply(q);

        t = (p.subtract(one)).multiply(q.subtract(one));

        e = new BigInteger("65537");
    }

    public static int generatePrivateKey()
    {
         d = e.modInverse(t);
         return d.intValue();
    }


    public static String decrypt()
    {
        String decrypted = "";
        int j = 0;
        for(int i = 0; i < cipherText.length(); i++){
            char c = cipherText.charAt(i);
            BigInteger bi1 = BigInteger.valueOf(c);
            BigInteger bi2 = bi1.modPow(d, n);
            j = bi2.intValue();
            c = (char) j;
            decrypted += c;
        }
        return decrypted;
    }
    public static void main(String[] args) {
        RSA rsa = new RSA();
        generatePrivateKey();
        decrypt();
    }
}

When I run this decryption program, all I get is a 309 character long string of "?"s. Why, and how do I fix this?

4

1 回答 1

-2
import math

from Crypto.Util import number
import libnum
import gmpy2

p=9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q=11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e=65537
c=83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034

n = p*q

# ed+k*(p-1)(q-1)=1
phif = (p-1)*(q-1)
d = gmpy2.gcdext(e,phif)[1]
print(d)

m = pow(c,d,n)
print(m)

d=56632047571190660567520341028861194862411428416862507034762587229995138605649836960220619903456392752115943299335385163216233744624623848874235303309636393446736347238627793022725260986466957974753004129210680401432377444984195145009801967391196615524488853620232925992387563270746297909112117451398527453977 m=5577446633554466577768879988

于 2021-08-25T16:40:16.900 回答