linux 加密解密文件小程序
代码见下面,编译之后就可以用;建议放在bash下,或者添加环境变量。
使用方法:encrypt <文件名>。两次输入密码。加密密码与解密密码不一致解码后就不是原文件了!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int decrypt(FILE *in,FILE *out);
int encrypt(FILE *in,FILE *out);
int passlen;
char pass[105],passa[105];
int main(int argc,char **argv)
{
if(argc != 2)
{
printf("\n请输入文件名进行加密或者解密!\n");
printf(" encrypt <inputfile>\n\n");
exit(0);
}
while(1)
{
printf("Enter password:");
system("stty -icanon");
system("stty -echo");
scanf("%s",pass);
system("stty icanon");
system("stty echo");
printf("\nEnter password again:");
system("stty -icanon");
system("stty -echo");
scanf("%s",passa);
system("stty icanon");
system("stty echo");
if(strcmp(pass,passa)==0) break;
printf("\nPassword is inconsistent\n");
}
printf("\n");
FILE *in = fopen(argv[1],"rb");
FILE *out = fopen("encrypt-tmp","w");
passlen=strlen(pass);
char code=0xAA;
for(int i=0;i<passlen;i++) pass[i]=pass[i]^code;
if(in == NULL || out == NULL)
{
fprintf(stderr,"%s\n","open file error!");
exit(1);
}
encrypt(in,out);
fclose(in);
fclose(out);
remove(argv[1]);
rename("encrypt-tmp",argv[1]);
return 0;
}
int encrypt(FILE *in,FILE *out)
{
if(in == NULL || out == NULL)
{
fprintf(stderr,"%s\n","file error!\n");
return -1;
}
char hex;
int i=0;
while(fread(&hex,1,1,in))
{
char s=pass[i];
hex = hex^s;
fwrite(&hex,1,1,out);
i++;
i%=passlen;
}
return 0;
}
linux 加密解密文件小程序的更多相关文章
- php AES cbc模式 pkcs7 128位加密解密(微信小程序)
PHP AES CBC模式PKCS7 128位加密 加密: $key = '1234567812345678'; $iv = '1234567890123456'; $message = '12345 ...
- 使用 gzexe 快速加密解密文件内容
使用 gzexe 快速加密解密文件内容 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.使用sshpass工具编写远程管理脚本 1>.安装依赖包 [root@node101 ...
- C# 加密解密文件
using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptograph ...
- base64加密解密文件
1 //字符串加密 -(void)demo1 { //普通的 8 bit二进制数据 NSString *str = @"hello world!"; //将字符串转换成二进制数据 ...
- DES 加密解密 文件工具类
public class DESEncrypt { /** 加密工具 */ private Cipher encryptCipher = null; /** 解密工具 */ private Ciphe ...
- linux 下启动jar小程序
下面是我的三个可运行jar程序 1.启动 采集话单文件应用程序 nohup java -jar gather.jar > logs/gather/console.out & 2.启动 ...
- GOLANG 加密,解密,GUID 小方法
golang的 MD5加密.BASE64解密 guid 的代码: /** * 用于加密,解密,(包含MD5加密和base64加密/解密)以及GUID的生成 * 时间: * zhifieya */ p ...
- (转载)linux中设备文件配置程序udev详解
如果你使用Linux比较长时间了,那你就知道,在对待设备文件这块,Linux改变了几次策略.在Linux早期,设备文件仅仅是是一些带有适当的属性集的普通文件,它由mknod命令创建,文件存放在/dev ...
- C#调用GPG命令进行加密解密文件操作
public void GPG() { string password = "1234567890"; System.Diagnostics.ProcessStartInfo ps ...
随机推荐
- jenkins 构建一个前端web项目
Jenkins发布web前端代码 “系统管理”“管理插件”“已安装” 检查是否有“Git plugin”和“Publish Over SSH”两个插件,如果没有,则需点击“可选插件”,找到它并安装 ...
- java中各种时间格式的转化
http://www.chinaitpower.com/A/2005-01-14/104881.html 使用java.util.Calendar返回间隔天数 static int g ...
- [转]如何用C++实现一个LRU Cache
[转自http://hawstein.com/posts/lru-cache-impl.html] LRU是Least Recently Used的缩写,意思是最近最少使用,它是一种Cache替换算法 ...
- USB协议[转]__总结得很好
一 枚举过程:◆ 用户将一个USB设备插入USB端口,主机为端口供电,设备此时处于上电状态.◆主机检测设备.◆集线器使用中断通道将事件报告给主机.◆主机发送Get_Port_Status(读端口状态) ...
- kernel&uboot学习笔记
uboot kernel uboot 1.Uboot编译流程分析: uboot是如何编译生成的? 2.根据include/configs/$(target).h可以生成include/autoconf ...
- Codeforces 467D Fedor and Essay bfs
题目链接: 题意: 给定n个单词. 以下有m个替换方式.左边的单词能变成右边的单词. 替换随意次后使得最后字母r个数最少,在r最少的情况下单词总长度最短 输出字母r的个数和单词长度. 思路: 我们觉得 ...
- 【Selenium + Python】之如何获取最新的报告以及os.path.getmtime与os.path.getctime的区别
import os def new_file(test_dir): #列举test_dir目录下的所有文件(名),结果以列表形式返回. lists=os.listdir(test_dir) #sort ...
- hdu 5538 House Building(长春现场赛——水题)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=5538 House Building Time Limit: 2000/1000 MS (Java/Others) ...
- eclipse转到IntelliJ IDEA 2017.1入坑指南
最近准备从eclipse转到IDE上去,由于eclipse占用的内存太大,而且IDE看着逼格还是比较大的,在转移项目的时候遇到好多的坑呀!在这里记录一下 关于:2017.1版本 之前装的是2016的版 ...
- DBUtils使用详解
https://blog.csdn.net/samjustin1/article/details/52220423 https://www.cnblogs.com/CQY1183344265/p/58 ...