예제 #1
0
    public Evento RSAencode(Evento aCodificar)
    {
        Debug.Log("Codificando mensaje...");
        // Aqui va el algoritmo RSA 8)
        BigInteger id = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aCodificar.id));
        BigInteger mat = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aCodificar.material));
        BigInteger x = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aCodificar.position.x.ToString()));
        BigInteger y = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aCodificar.position.y.ToString()));
        BigInteger z = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aCodificar.position.z.ToString()));

        /*if (id > this.publicKey || mat > this.publicKey || x > this.publicKey || y > this.publicKey || z > this.publicKey)
        {
            throw new System.ArgumentException("Parameter cannot be encoded", "original");
        }*/

        string cId = ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(id, this.e, this.publicKey).ToByteArray());
        string cMat = ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(mat, this.e, this.publicKey).ToByteArray());
        /*float cX = float.Parse(ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(x, this.e, this.publicKey).ToByteArray()));
        float cY = float.Parse(ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(y, this.e, this.publicKey).ToByteArray()));
        float cZ = float.Parse(ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(z, this.e, this.publicKey).ToByteArray()));*/
        float cX = System.BitConverter.ToSingle(BigInteger.ModPow(x, this.e, this.publicKey).ToByteArray(), 0);
        float cY = System.BitConverter.ToSingle(BigInteger.ModPow(y, this.e, this.publicKey).ToByteArray(), 0);
        float cZ = System.BitConverter.ToSingle(BigInteger.ModPow(z, this.e, this.publicKey).ToByteArray(), 0);
        Evento ev = new Evento(cId, cMat, new Vector3(cX, cY, cZ));
        return ev;        
    }
예제 #2
0
    public Evento RSAdecode(Evento aDecodificar)
    {
        // Aqui va el algoritmo RSA 8)
        BigInteger id = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aDecodificar.id));
        BigInteger mat = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aDecodificar.material));
        BigInteger x = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aDecodificar.position.x.ToString()));
        BigInteger y = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aDecodificar.position.y.ToString()));
        BigInteger z = new BigInteger(ASCIIEncoding.ASCII.GetBytes(aDecodificar.position.z.ToString()));

        if (id > this.publicKey)
        {
            throw new System.ArgumentException("Parameter cannot be encoded", "original");
        }

        string dId = ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(id, this.privateKey, this.publicKey).ToByteArray());
        string dMat = ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(mat, this.privateKey, this.publicKey).ToByteArray());
        /*float dX = float.Parse(ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(x, this.privateKey, this.publicKey).ToByteArray()));
        float dY = float.Parse(ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(y, this.privateKey, this.publicKey).ToByteArray()));
        float dZ = float.Parse(ASCIIEncoding.ASCII.GetString(BigInteger.ModPow(z, this.privateKey, this.publicKey).ToByteArray()));*/
        float dX = System.BitConverter.ToSingle(BigInteger.ModPow(x, this.e, this.publicKey).ToByteArray(), 0);
        float dY = System.BitConverter.ToSingle(BigInteger.ModPow(y, this.e, this.publicKey).ToByteArray(), 0);
        float dZ = System.BitConverter.ToSingle(BigInteger.ModPow(z, this.e, this.publicKey).ToByteArray(), 0);
        Evento ev = new Evento(dId, dMat, new Vector3(dX, dY, dZ));
        return ev;
    }
예제 #3
0
 public static BigInteger ModPow(this BigInteger value, BigInteger exponent, BigInteger modulus)
 {
     return(BigInteger.ModPow(value, exponent, modulus));
 }