加密:从s1字符串中每取一个字符,在CS表中查找有无该明码字符, 若有,将对应密码字符放入s2中,若无,直接将原字符放入s2中

#include<stdio.h>
#include<string.h>

char CS[2][10] = { "aceghjlnp","fonptiude" };
void encode(char array1[80], char array2[80])
{
	char *p, *pt, *cs1, *cs2;
	p = array1;
	pt = array2;


	while (*p != '\0')
	{
		cs1 = &CS[0][0];
		cs2 = &CS[1][0];
		while (*cs1 != '\0')//指针是有指向内容的,并不是null
		{
			if (*p == *cs1)
				*p = *cs2;
			cs1++;
			cs2++;
		}
		*pt = *p;
		p++;
		pt++;
		
	}
	*pt = '\0';

}
void main()
{
	char ts[80] = "those words will be changed", td[80];
	encode(ts, td);
	puts(td);
	getchar();
	getchar();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您的问题是如何使用 Python 实现上位机加密,我会尽力回答。首先,您需要用到一些 Python 加密库,比如 hashlib 和 cryptography。以下是实现步骤: 1. 判断注册文件是否存在,如果不存在则获取 C 盘序列号和当前时间,将它们组合加密生成明码。 ```python import hashlib import datetime import os def get_serial_number(): return os.popen('wmic diskdrive get serialnumber').read().split()[-1] def encrypt(message): return hashlib.sha256(message.encode()).hexdigest() def generate_activation_code(): serial_number = get_serial_number() current_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S') plain_text = f'{serial_number}{current_time}' activation_code = encrypt(plain_text) return activation_code ``` 2. 将明码发送给客户,客户将明码加上限定的使用时间和自定义的字符串加密生成密码,发送给开发者。 ```python from cryptography.fernet import Fernet def generate_password(activation_code, expiration_date, custom_string): key = Fernet.generate_key() cipher_suite = Fernet(key) plain_text = f'{activation_code}{expiration_date}{custom_string}'.encode() password = cipher_suite.encrypt(plain_text) return password, key ``` 3. 客户输入密码后,上位机生成注册文件,其包含加密后的 C 盘序列号、时限和自定义的字符串。 ```python import json def generate_registration_file(serial_number, expiration_date, custom_string, key): registration_info = { 'serial_number': encrypt(serial_number), 'expiration_date': encrypt(expiration_date), 'custom_string': encrypt(custom_string) } with open('registration_file.txt', 'w') as f: f.write(json.dumps(registration_info)) with open('key.key', 'wb') as f: f.write(key) ``` 4. 上位机每次打开与注册文件进行校对,解密注册文件的注册码,判断其的 C 盘序列号是否与本机的 C 盘序列号一致,若一致,则判断其的时限是否到期,若未到期则可正常打开上位机。 ```python def check_registration(): try: with open('registration_file.txt', 'r') as f: registration_info = json.load(f) with open('key.key', 'rb') as f: key = f.read() serial_number = registration_info['serial_number'] expiration_date = registration_info['expiration_date'] custom_string = registration_info['custom_string'] cipher_suite = Fernet(key) plain_text = cipher_suite.decrypt(serial_number).decode() if plain_text != get_serial_number(): return False plain_text = cipher_suite.decrypt(expiration_date).decode() expiration_datetime = datetime.datetime.strptime(plain_text, '%Y%m%d%H%M%S') if datetime.datetime.now() > expiration_datetime: return False return True except: return False ``` 以上是一个简单的实现,您可以根据需要进行修改和完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值