| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 489 人关注过本帖
标题:文件的加密和解密
只看楼主 加入收藏
北纬以北
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2014-12-27
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
文件的加密和解密
#include"sequence.cpp"
#define MAX 100
char str[MAX];
int readData()
{
    FILE *fp;
    int i=0;
    if((fp=fopen("a.txt","r"))==NULL)
    {
        printf("can not open file");
        exit(1);
    }
    fscanf(fp,"%s",str);
    puts(str);
    fclose(fp);

    return i;
}
int main()
{
    int n;
    int i;
    printf("请输入密码:");
    scanf("%d",&n);
    for(i=0;i<readData();i++)
    {
        str[i]=str[i]+n;
    }
    str[i]='\0';
    StackNode s;
    Init();
    for(i=0;i<readData();i++)
    {
        Push(&s,str[i]);
    }
    i=0;
    while(!Empty (&s))   
    {
        str[i]=Pop(&s);
        i++;
    }
    str[i]='\0';
    printf("加密结果为:\n");
    for(i=0;i<readData();i++)
    {
        printf("%s",&str[i]);
    }
    return 0;
}感觉像是进入了死循环,帮忙看一下
搜索更多相关主题的帖子: include 输入密码 return 加密 file 
2014-12-29 10:30
muyoucumian
Rank: 3Rank: 3
等 级:等待验证会员
帖 子:80
专家分:126
注 册:2014-8-30
收藏
得分:5 
一行注释都没有,看都不想看
2014-12-29 16:43
enning
Rank: 1
等 级:新手上路
帖 子:1
专家分:5
注 册:2014-12-29
收藏
得分:5 
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
char str[MAX];
typedef int datatype;
typedef  struct  snode{
    datatype  info;
    struct  snode *next;
} StackNode,  *LinkStack;
LinkStack  Init( )
{  LinkStack  top;
    top=(LinkStack)malloc(sizeof(StackNode));
    top->next=NULL;
    return  top;
}
int  Empty (LinkStack  top)
{  return  top->next==NULL;
}
void  Push (LinkStack  top, datatype  x)
{  LinkStack  p;
    p=(LinkStack)malloc(sizeof(StackNode));
    p->info=x;
    p->next=top->next;
    top->next=p;
}
datatype  Pop (LinkStack  top)
{  LinkStack  p;  datatype  x;
    if ( Empty (top) )
    {
        printf("\nThe sequence stack is empty!");
        exit(1);
    }   
    p=top->next;
    x=p->info;
    top->next=p->next;
    free(p);
    return  x;
}
datatype  GetTop (LinkStack  top)
{
    if ( Empty(top) )
    {
        printf("\nThe sequence stack is empty!");
        exit(1);
    }   
    return  top->next->info;
}
void readData()
{
    FILE *fp;
    if((fp=fopen("a.txt","r"))==NULL)
    {
        printf("can not open file");
        exit(1);
    }
    fscanf(fp,"%s",str);
    puts(str);
    fclose(fp);
}
int main()
{
    int n;
    int i;
    printf("请输入密码:");
    scanf("%d",&n);
    readData();
    for(i=0;str[i]!='\0';i++)
    {
        str[i]=str[i]+n;
    }
    str[i]='\0';
    LinkStack s;
    s=Init();
    for(i=0;str[i]!='\0';i++)
    {
        Push(s,str[i]);
    }
    i=0;
    while(!Empty (s))   
    {
        str[i]=Pop(s);
        i++;
    }
    str[i]='\0';
    printf("加密结果为:\n");
    for(i=0;str[i]!='\0';i++)
    {
        printf("%c",str[i]);
    }
    printf("\n");
    return 0;
}
2014-12-29 16:45
快速回复:文件的加密和解密
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017274 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved