aan 算法 c 语言示例


static int SpreSC[64]
={
  16384, 22725, 21407, 19266,  16384, 12873, 8867,  4520,
  22725, 31521, 29692, 26722,  22725, 17855, 12299, 6270,
  21407, 29692, 27969, 25172,  21407, 16819, 11585, 5906,
  19266, 26722, 25172, 22654,  19266, 15137, 10426, 5315,
  16384, 22725, 21407, 19266,  16384, 12873, 8867,  4520,
  12873, 17855, 16819, 15137,  25746, 20228, 13933, 7103,
  17734, 24598, 23170, 20853,  17734, 13933, 9597,  4892,
  18081, 25080, 23624, 21261,  18081, 14206, 9785,  4988
};

/*
    use this table to multiply the block[j] in the decode_macroblock
 stage;
 after multiply,shift to right 13 bits; (17-4)

*/

#define C2   30274       // 2 COS (PI/8) 1.84776
#define C4   23171       // SQRT(2)  1.41421
#define C6   12540       // 2 SIN (PI/8)  0.76537
#define C6pC2   42814    file://C6+C2   2.61313
#define C6sC2   (-17734) //        -1.08239
#define RC0    14
#define RC1    18
#define ROUND   (1<<(RC1-1))

//  do 80 times of multiply; fastidct :176;

#define idct_unit(a,b) {x4 = x5 - x3;        /
               t1 = x5 + x3;        /
                     x3 = (x2+x6)<<RC0;   /
                     x2 = (x2-x6)*C4-x3;  /
                     t0 = x1 + x7;        /
                        x6=  x1 - x7;        /
                        x7=  (t0 + t1)<<RC0; /
                     x5 = (t0 - t1)*C4;   /
                   t0=C6*(x4+x6);       /
                      x4=C6sC2*x4-t0;      /
                       x6=C6pC2*x6-t0;      /
                t0=x6-x7;            /
                    x1=(a-b)<<RC0;       /
                   t1=t0-x5;            /
                  x6=(a+b)<<RC0;       /
                  x0=x4-t1;            /
                    x4=x3+x6;            /
                     x6-=x3;              /
                     x3=x1+x2;            /
                    x5=x1-x2;            }


static void IDCTaan_c(short* block)
{
 int x0,x1,x2,x3,x4,x5,x6,x7;
 int t0,t1;
 short *blk;
// Field one
 blk  =  block;
 for(int i=0; i<8; i++)
 {
  if (!(  (x1 = blk[1]) 
           | (x2 = blk[2])
           | (x3 = blk[3])
           | (x4 = blk[4])
           | (x5 = blk[5])
           | (x6 = blk[6])
           | (x7 = blk[7])))
  {
     // blk[0]=
       blk[1]=blk[2]=blk[3]=blk[4]
           =blk[5]=blk[6]=blk[7]=(blk[0]);
  }
        else
  {

   idct_unit(blk[0],blk[4])

      blk[0]=(x4+x7)>>RC0 ;
      blk[7]=(x4-x7)>>RC0 ;
      blk[1]=(x3+t0)>>RC0 ;
      blk[6]=(x3-t0)>>RC0 ;
      blk[2]=(x5-t1)>>RC0 ;
      blk[5]=(x5+t1)>>RC0 ;
      blk[3]=(x6-x0)>>RC0 ;
      blk[4]=(x6+x0)>>RC0 ;
  }
  blk+=8;
 }

file://field two
    blk=block;
 for ( i=0; i<8; i++)
 {
  if (!((x1 = blk[8])
   | (x2 = blk[16])
   | (x3 = blk[24])
   | (x4 = blk[32])
   | (x5 = blk[40]) 
   | (x6 = blk[48])
   | (x7 = blk[56])))
  {
            blk[0]=blk[8]=blk[16]=blk[24]
    =blk[32]=blk[40]=blk[48]=blk[56]=
                                      iclp[blk[0]>>4];
  }
  else
  {
   idct_unit(blk[0*8],blk[4*8])

   blk[0*8]=iclp[(x4+x7+ROUND)>>RC1];
      blk[7*8]=iclp[(x4-x7+ROUND)>>RC1];
      blk[1*8]=iclp[(x3+t0+ROUND)>>RC1];
      blk[6*8]=iclp[(x3-t0+ROUND)>>RC1];
      blk[2*8]=iclp[(x5-t1+ROUND)>>RC1];
      blk[5*8]=iclp[(x5+t1+ROUND)>>RC1];
      blk[3*8]=iclp[(x6-x0+ROUND)>>RC1];
      blk[4*8]=iclp[(x6+x0+ROUND)>>RC1];
  }
     blk++;
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是RSA加密算法的C++语言代码示例: ```cpp #include <iostream> #include <cmath> using namespace std; int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int modPow(int base, int exponent, int modulus) { int result = 1; while (exponent > 0) { if (exponent % 2 == 1) { result = (result * base) % modulus; } base = (base * base) % modulus; exponent = exponent / 2; } return result; } int main() { int p, q, n, phi, e, d, message, ciphertext, plaintext; // Step 1: Choose two prime numbers p = 17; q = 19; // Step 2: Compute n = p * q n = p * q; // Step 3: Compute phi(n) = (p - 1) * (q - 1) phi = (p - 1) * (q - 1); // Step 4: Choose an integer e such that 1 < e < phi(n) e = 5; while (gcd(e, phi) != 1) { e++; } // Step 5: Compute d such that d * e = 1 (mod phi(n)) d = 1; while ((d * e) % phi != 1) { d++; } // Step 6: Encrypt the message using the public key (e, n) message = 123; ciphertext = modPow(message, e, n); cout << "Encrypted message: " << ciphertext << endl; // Step 7: Decrypt the ciphertext using the private key (d, n) plaintext = modPow(ciphertext, d, n); cout << "Decrypted message: " << plaintext << endl; return 0; } ``` 该示例实现了RSA加密算法的核心步骤,包括: 1. 选择两个质数 p 和 q 2. 计算 n = p * q 3. 计算 phi(n) = (p - 1) * (q - 1) 4. 选择一个整数 e 使得 1 < e < phi(n),且 gcd(e, phi(n)) = 1 5. 计算 d 使得 d * e = 1 (mod phi(n)) 6. 使用公钥 (e, n) 加密消息 7. 使用私钥 (d, n) 解密密文 在实际应用中,需要考虑到安全性和性能等因素,例如选择更大的质数和密钥长度等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值