口算密码

口算密码

可以得到a=15,b=6
所以得到的 a − 1 × a = 1 ( m o d 26 )     a − 1 = 26 − 15 = 11 , 函 数 为 f ( x ) = a − 1 ( x − b ) a^{-1}\times a=1(mod26) \ \ \ a^{-1} =26-15=11,函数为f(x)=a^{-1}(x-b) a1×a=1(mod26)   a1=2615=11,f(x)=a1(xb)
有 26 k + 15 a − 1 = 1 有26k+15a^{-1}=1 26k+15a1=1
根据拓展欧几里得算法求出 a − 1 = 7 a^{-1}=7 a1=7
得到密码

代码

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<map>
using namespace std;
#define N 1000000
char A[N] = {"fho aoc wq kiexufob wq g siiz wtjotfwit"};
char B[N] = {"abcdefghijklmnopqrstuvwxyz"};
int gcd;
void ex_gcd(int a,int b,int &x,int &y){
	if(b){
	    ex_gcd(b,a%b,x,y);
	    int t=x;
	    x=y;
	    y=t-(a/b)*y;
	}
	else{
	    x=1,y=0;
	    gcd=a;
	}
	return;
}
int main(){
    int n=strlen(A);
    int a = 15, b = 6;
    const int mod=26;
    int x, y;
    ex_gcd(26, 15, x, y);
    cout << y<<endl;
    a = 7;
    for (int i = 0; i < n;i++){
        if(A[i]==' ')
            continue;
        int t = a * (A[i] - 'a' - b+26);
        t%=mod;
        cout << B[t];
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值