예제 #1
0
파일: ecdh.c 프로젝트: rutvik11/nslab
int main()
{
    
    printf("\n\nEnter the values of a and b - ");
    scanf("%d%d",&a,&b);
    
    printf("\nEnter the prime number - ");
    scanf("%d",&p);
    
    
    printf("\nEnter the values of xp and yp - ");
    scanf("%d%d",&xp,&yp);
    
    na = rand()%10+2;
    printf("\nValue of Na - %d",na);
    nb = rand()%10+2;
    printf("\nValue of Nb - %d",nb);
    
    int public_key[4], private_key[4];
    publickey(na);
    public_key[0] = xq;
    public_key[1] = yq;
    
    printf("\nPublic key of A - (%d ,%d)\n\n",public_key[0],public_key[1]);
    
    publickey(nb);
    public_key[2] = xq;
    public_key[3] = yq;
    
    printf("Public key of B - (%d ,%d)\n\n",public_key[2],public_key[3]);
    
    secretkey(public_key[2], public_key[3], na);
    private_key[0] = xq;
    private_key[1] = yq;
    
    printf("\nShared Secret key of A - (%d ,%d)\n\n",private_key[0],private_key[1]);
    
    secretkey(public_key[0], public_key[1], nb);
    private_key[2] = xq;
    private_key[3] = yq;
    
    printf("\nShared Secret key of B - (%d ,%d)\n\n",private_key[2],private_key[3]);
    
    
    
    
    return 0;
    
}
예제 #2
0
void CMessagePushMgr::XG_Push_Message(ETerminalType ttype, string account, string message)

{
	string accessid("");
	string secretkey("");
	int env = 0;

	if (ttype == Terminal_IOS)
	{
		accessid = m_config.sXG_IOS_AccessID;
		secretkey = m_config.sXG_IOS_SecretKey;
		env = m_config.iXG_IOS_Environment;
	}
	else
	{
		accessid = m_config.sXG_Android_AccessID;
		secretkey = m_config.sXG_Android_SecretKey;
	}


	std::string url = "http://openapi.xg.qq.com/v2/push/single_account";
	xg_url xgurl(accessid, secretkey, account, message, env);
	std::string strParas = xgurl.get_strParams();

	{
		ostringstream os;
		string log("");
		os << "send http post,"
			<< "account=" << account
			<< ",full url = " << url << "?" << strParas
			<< ",msg=" << message;
		log = os.str();
		m_logfunc(log);
	}

	m_AsyncHttpClient_ptr->HttpPost(url, strParas,
		[&](bool bOk, std::string& strRsp)
	{
		stringstream os;
		string log("");
		os << "http post response: bOk="
			<< (bOk ? "true" : "false")
			<< ",strRsp=" << strRsp;
		log = os.str();
		m_logfunc(log);

		/*
		if (bOk)
		{
			Json::Reader reader;
			Json::Value root;
			reader.parse(strRsp, root);

			if (root != Json::nullValue)
			{
				int ret_code = root.get("ret_code", 0).asInt();
				if (ret_code != 0)
				{
					string err_msg = root.get("err_msg", "").asString();
					stringstream os;
					string log("");
					os << "http post response:ret_code="<<ret_code
						<<",err_msg="<<err_msg;
					log = os.str();
					m_logfunc(log);

				}
			}

		}*/
	});
}
int main()
{
	int p,g,a,b,t;
	unsigned long long int A, B, secret1, secret2;
	printf("*********Klasik Diffie Hellman Anahtar Degisimi*********\n\n");
	printf("NOT  :  'g' bir tamsayi, 'p' bir asal sayi ve 'p'-1>'g' olmalidir. \n\n");
	
	tekrar2:
	printf("Lutfen ortak 'g' taban degerini giriniz  :  "); 
	scanf("%d", &g);
	tekrar:
	printf("Lutfen ortak 'p' mod degerini giriniz    :  "); 
	scanf("%d", &p);
	
	t=asal(p);
	if(t==1)
	goto tekrar;
	t=aralarindaasal(g,p);
	if(t==1)
	goto tekrar2;
	
	printf("\n\tg  :  %d\n\tp  :  %d\n", g,p);
	
	printf("\nClient gizli degerini giriniz  :  "); 
	scanf("%d", &a);
	printf("Server gizli degerini giriniz  :  ");
	scanf("%d", &b);
	
	printf("\n\ta  :  %llu\n\tb  :  %llu\n", a,b);

	A=publickey(g,a,p);
	B=publickey(g,b,p);
	
	printf("\nPublic Deger Hesaplama=>    A  :  g^a mod p\n");
	printf("                            B  :  g^b mod p\n");
	printf("\nClient public degeri  =>    A  :  %d^%d mod %d\n", g,a,p);
	printf("Server public degeri  =>    B  :  %d^%d mod %d\n\n", g,b,p);
	
	printf("\tA  :  %llu\n\tB  :  %llu\n\n", A,B);

	printf("Gizli Deger Hesaplama => Client  :  B^a mod p  =  g^ba mod p\n");
	printf("                         Server  :  A^b mod p  =  g^ab mod p\n\n");
	printf("Client gizli degeri   =>    s1   :  %llu^%d mod %d\n", B,a,p);
	printf("Server gizli degeri   =>    s2   :  %llu^%d mod %d", A,b,p);
	secret1=secretkey(B,a,p);
	secret2=secretkey(A,b,p);
	
	printf("\n\n\ts1  :  %llu\n\ts2  :  %llu\n", secret1,secret2);
	
	if(secret1!=secret2)
	printf("\n\n's' degerleri esit cikmadi. Islemlerde bir sorun olabilir. \nKontrol ettikten sonra, tekrar deneyiniz.\n\n");
	
	else
	printf("\nOrtak gizli deger     =>    s  :  %llu",secret1);
	
	printf("\n\nClient'in Bildigi Degerler  :  g, p, a, A, B, s\n");
	printf("Server'in Bildigi Degerler  :  g, p, b, B, A, s");
	
	printf("\n\n\n\t*******Tolga Akkapulu*******\n\thttp://www.tolgaakkapulu.com");
	
	getch();
}