先用python 做一個文本文件 (一個學號列表)
python 代碼:
[root@localhost kuing]# cat input.py
#!/usr/bin/env python
f = open('design.txt','w+')
for i in range(10001,200001):
f.write('%d\n' %i)
f.close()
沒錯 就是這麼簡單...
然後就是這些東西..
...
199998
199999
200000
接下來 寫c語言代碼:
[root@localhost kuing]# cat input.c
#include<stdio.h>
#include<stdlib.h>
int main(){
FILE *fp;
FILE *temp;
char filename[30];
char ch;
char strbuf[256];
printf("please input your filename:");
gets(filename);
filename[29] = '\n';
if ((fp = fopen(filename,"rb")) == NULL){
printf("error!\n");
return -1;
}
if ((temp = fopen("temp.txt","wb+")) == NULL){
printf("create file error!\n");
}
while(!feof(fp)){
ch = fgetc(fp);
if((int)ch != 0 && (int)ch != 0){
ch = ~ch;
ch = ch << 5;
fputc(ch,temp);
}
}
fclose(temp);
fclose(fp);
sprintf(strbuf,"rm %s",filename);
system(strbuf);
sprintf(strbuf,"mv temp.txt %s",filename);
system(strbuf);
return 0;
}
然後用在Linux系統下 用gcc編譯 的時候 出現gets警告輕忽略 Linux下是不建議這種寫法的
但是 如果換成 fgets() 又要解決符號問題 比較麻煩 所以請忽略..
然後 運行
請輸入要加密的文件
[root@localhost kuing]# ./input
please input your filename:design.txt
...
加密後類似於這樣..
φφφφφφφǐφǎφφφφǐφǐφǐφǐφǐφǎφǎφǎφωǎφχǎφǎφǎφǎφǎφǎφφφφφφφφφφφφφˋφˉφˇφφφφφφφφφφφφφφφφǐφǎφφφ ...
其實這就是這把字符按位取反 如果程序反過來運行一下 就會解密其中的內容..
..