الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج تشفير بلغة السي أرجو التعليق..

بدأه Gadori في 14 فبراير 2009 · 5 رد · 10,265 مشاهدة · في لغة C و ++C
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه

انا مشترك جديد في المنتدى

ادرس الهندسة الالكترونية في بداية السنة الرابعة

من عشاق البرمجة بس اعتبر نفسي مبتدئ

تعلمت السي و السي++ في الجامعة

كتبت برنامج بلغة السي++ لتشفير الملفات النصية (بأي لغة تقريبا) التي بامتداد

txt

هذا البرنامج يكون نسخة مشفرة من الملف الاصلى وهي عبارة عن مصفوفات من الارقام

في كل لحظة تشفر فيها الملف تكون النسخة المشفرة مختلفة عن نسخة شفرت في لحظة اخرى لنفس الملف لتصعب فك الشفرة

في البرنامج مجموعة من الخيارات تتضمن تغيير كلمة المرور التي تطلب عند فك التشفير

عند ادخال كلمة السر خطا 3 مرات متتالية يتوقف البرنامج لمدة دقيقة (لتجريب البرنامج ) يمكن زيادة المدة بالمتغير

stop_t

في كود البرنامج مثل فكرة رمز الحماية في الجوالات فلايسمح لك بادخال الباسوورد حتى تنتهي المدة الزمنية

وهناك مجموعة اخرى من الوظائف للمتغيرات ممكن اذكرها لمن يريد الاستزادة

هذا البرنامج كتبته بدون الرجوع لاي مرجع بالنسبة للسي او التشفير ماعدا الاوامر الاساسية اللي اتعلمتها

يعني كل البرنامج عبارة عن افكار شخصية فاعتقد انه البرنامج بدائي جدا

وبعد ما كتبته اكتشفت انه التشفير علم مستقل بذاته

ارجو انه تجربوا البرنامج وتعطوني رايكم

سمعت انه في برامج تدمج الشفرة في صورة بدون ان تلاحظ اي تغيير في الصورة

لو في احد عنده اي فكرة عن هذه الطريقة ارجو ان ينير عقولنا

وابغى اعرف كيف ممكن اكتب برنامج يشفر ملفات الصوت والصورة ؟

آسف للاطالة ..

كلمة السر الابتدائية للبرنامج 00000

اولا كود برنامج التحميل (لا يعمل برنامج التشفير بدون تشغيل هذا البرنامج ويمكن استخدامه عند نسيان كلمة السر لتصبح 00000 )

** لو استطاع اي شخص آخر الحصول على برنامج التحميل فلن تكون هناك فائدة للباسوورد

كود برنامج التحمبيل

setup program


#include<stdio.h>
#include<stdlib.h>
#include<sys\timeb.h>
#include<iostream.h>
#include<string.h>

const int s3=23;

void pwait(void);

void main()
{
FILE *sorce;
char str[12]="00000";
int n=0,i,x;
struct timeb tm;
long t;
char setup_f[]="C:\\c132104.txt";

sorce=fopen(setup_f,"w+");
fprintf(sorce,"%d ",n+s3);
fprintf(sorce,"%d ",strlen(str));
for(i=0;i
fprintf(sorce,"%d ",str+s3);
ftime(&tm);
fprintf(sorce,"%ld ",tm.time);
fclose(sorce);

sorce=fopen(setup_f,"r");
fscanf(sorce,"%d",&n);
n=n-s3;

fscanf(sorce,"%d",&x);
str[x]='\0';

for(i=0;str!='\0';i++)
{
fscanf(sorce,"%d",&x);
str=x-s3;
}
fscanf(sorce,"%ld",&t);
fclose(sorce);
printf("\n installing MY TEXT ENCODER ... ");
pwait();
cout<<<"\n setup has been completed";


fclose(sorce);
}

void pwait(void)
{
char p[8]={'|','//','-','\\','|','//','-','\\'};
struct timeb tm1,tm2;
ftime(&tm1);
for (int i=0;;i++)
{
printf("%c",p[i%strlen(p)]);
ftime(&tm2);
printf("%c",8);
if(labs(tm2.time-tm1.time)>=4) break;
}
}

وهنا كود برنامج التشفير

**يمكن ان يكون لكل شخص نسخته الخاصة من البرنامج بحيث لا تفك نسخة شفرة نسخة اخرى وذلك بتغيير رقمين فقط في الكود

كود برنامج التشفير وفك التشفير


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<sys\timeb.h>
const int s1=132,s2=104;
const int s3=23,err=3,err2=10,err3=30;
float stop_t=(1*60); \\ time in seconds ( 1 min * 60) = 60 sec
char setup_f[]="C:\\c132104.txt";
struct timeb tm;

int get_pw(char*);
void set_pwf(char pw[12],int n);

void scrn(void);
void pwait(void);
void rnd(FILE **codp);
void toggle(int *y);
void endp(void);
int check_f_n(char nam[30],int x);
int pw_op(int chos);


void main() ////////////// main
{
// encoder
FILE *sorce,*cod;
int i,y;
int j;
char str[500],sorc[30],nam[30],coded[30];

//decoder
FILE *decod;
int x,e_cod[3];
char d_cod[30];
MENU:
scrn();
if(fopen(setup_f,"r")==NULL)
{
printf("\n\n ** NOT INSTALLED ** install and then restart the program");
exit(0);
}
do
{
strcpy(str,"");
strcpy(sorc,"");
strcpy(nam,"");
strcpy(coded,"");
strcpy(d_cod,"");

printf("\n Press 1 to code a text file.");
printf("\n Press 2 to decode a code file.");
printf("\n Press 3 to change your password.");
printf("\n Press 4 to activate or deactivate your password.");
printf("\n Press 5 to exit the program.\t\t: ");
i=getche();
switch(i)
{
case ('1'): //////////////////////////////// start encoder
scrn();
y=s1;
j=0;
for(;;)
{
i=0;
strcpy(sorc,"D:\\");
printf("\nCopy or move your file to (( D:\\ )) and then ,");
printf("\nEnter your file name : ");
scanf("%s",nam);
check_f_n(nam,1);
strcat(sorc,nam);
// printf("# %s #",sorc);
sorce=fopen(sorc,"r");
if(sorce==NULL)
{
printf("\nCan not find your file in (( D:\\ )) !!\n");
do
{
printf("\nPress 1 to enter your file name again.");
printf("\nPress 2 to restart the program.\t\t: ");
i=getche();
switch(i)
{
case ('1'): break;
case ('2'): goto MENU;
default: printf("\nInvalid chois !\n");i='3';break;
}
}while(i=='3');
}
else break;
}
////////////////////////////////

do
{
i=0;
strcpy(coded,"D:\\");
printf("\n\nThe code file will be in (( D:\\ ))\n"
" Enter the code file name : ");
scanf("%s",nam);
check_f_n(nam,2);
strcat(coded,nam);
cod=fopen(coded,"r");
if(cod!=NULL)
{
printf("\nThe file (( %s )) is alrady exist !\n",coded);
do
{
printf("\nPress 1 to enter the code file name again.");
printf("\nPress 2 to overwrit the file.");
printf("\nPress 3 to restart the program.\t\t: ");
i=getche();
switch(i)
{
case ('1'): break;
case ('2'): break;
case ('3'): goto MENU;
default: printf("\nInvalid chois !\n");i='4';break;
}
}while(i=='4');
}
else break;
}while(i!='2');

////////////////////////////////// encoder
cod=fopen(coded,"w+");
y=s1;
///////////////////// random
rnd(&cod);
fprintf(cod,"%d\t",s1+s2);

if(sorce!=NULL)
{
while(!feof(sorce))
{
strcpy(str,"");
fgets(str,500,sorce);
for(i=0;str!='\0';i++)
{
fprintf(cod,"%d\t",str+y);
toggle(&y);
}
fprintf(cod,"%d\t",32+y); // space
toggle(&y);
}
if(y==s1)
fprintf(cod,"%d\t%d\t%d\t",7+s1,7+s2,7+s1);
else
if(y==s2)
fprintf(cod,"%d\t%d\t%d\t",7+s2,7+s1,7+s2);

rnd(&cod);

printf("\n");

fclose(sorce);
fclose(cod);
printf("\ncoding is running ... ");
pwait();
scrn();
printf("\n\n\t\tYour file has been encoded successfully\n");
printf("\n\nThe text file \t%s\n",sorc);
printf("The code file \t%s\n",coded);
printf("\n Now you may delete the text file\n and keep the code file\n");
}
getch();
scrn();
break;

case ('2'): /////////////////////// start decoder

scrn();
for(j=3;j>0;--j)
e_cod[j]=0;
y=s1;

for(;;)
{
i=0;
strcpy(coded,"D:\\");
printf("\nCopy or move your code file to (( D:\\ )) and then ,");
printf("\nEnter your code file name : ");
scanf("%s",nam);
strcat(coded,nam);
// printf("\n# %s # ",coded);
cod=fopen(coded,"r");
if(cod==NULL)
{
printf("\nCan not find your file in (( D:\\ ))!!\n");
do
{
printf("\nPress 1 to enter your code file name again.");
printf("\nPress 2 to restart the program.\t\t: ");
i=getche();
switch(i)
{
case ('1'): break;
case ('2'): goto MENU;
default: printf("\nInvalid chois !\n");i='3';break;
}
}while(i=='3');
}
else break;
}
////////////////////////////////
if(!pw_op(0))
{
fopen(coded,"w");
printf("\n\n\t\t#*#*#*#*#*# erased #*#*#*#*#*#*#\n");
getch();
}
else
{
do
{
i=0;
strcpy(d_cod,"D:\\");
printf("\n\nThe decoded file will be in (( D:\\ ))\n"
" Enter the decoded file name : ");
scanf("%s",nam);
check_f_n(nam,1);
strcat(d_cod,nam);
decod=fopen(d_cod,"r");
if(decod!=NULL)
{
printf("\nThe file (( %s )) is alrady exist !\n",d_cod);
do
{
printf("\nPress 1 to enter the decoded file name again.");
printf("\nPress 2 to overwrit the file.");
printf("\nPress 3 to restart the program.\t\t: ");
i=getche();
switch(i)
{
case ('1'): break;
case ('2'): break;
case ('3'): goto MENU;
default: printf("\nInvalid chois !\n");i='4';break;
}
}while(i=='4');
}
else break;
}while(i!='2');
printf("\n");
//////////////////////////// decoder goto

decod=fopen(d_cod,"w");

do

fscanf(cod,"%d",&x);
while (x!=s1+s2&&!feof(cod));
if(feof(cod)) // if undefined code file
{
printf("\n ERROR undefined code file\n");
getch();
}
else
{
x=s1+s2;
j=0;
y=s1;

while(!feof(cod))
{
fscanf(cod,"%d",&x);
if(x==7+y)
{
e_cod[j]=x;
j++;

toggle(&y);
fscanf(cod,"%d",&x);
if(x==7+y)
{
e_cod[j]=x;
j++;

toggle(&y);
fscanf(cod,"%d",&x);
if(x==7+y)
{
e_cod[j]=x;
j++;
}
}
}

if (j==3)
{break;}
else
if(j>0)
{
for(i=0;i<j;i++)
fprintf(decod,"%c",x-y);
j=0;
}
else
{
fprintf(decod,"%c",x-y);
if(j==3)
{
for(int i=0;i<3;i++)
printf("%c",8);
break;
}
}
toggle(&y);
}

fclose(decod);
fclose(cod);

printf("\ndecoding is running ... ");
pwait();
scrn();

if(x==s1+s2||j!=3)
printf("\n\t\tERROR can not decode your file\n");
else
{
printf("\n\t\tYour file has been decoded successfully\n");
printf("\n\nThe code file \t%s\n",coded);
printf("The text file \t%s\n",d_cod);
}

getch();
} // defined code file
} // not erased
scrn();
break;

case ('3'): ///////////////////////////// change pw
pw_op(3);
scrn();
while(1)
{
printf("\n Enter your new password : ");

for(i=0;;)
{
str=getch();
if(str==13)
{str='\0'; break;}
else
if(str==8)
{
if(i!=0)
{
printf("%c",8);
i--;
}
continue;
}
else
printf("*");
i++;
}


printf("\n Enter your new password again: ");
for(i=0;;)
{
nam=getch();
if(nam==13)
{nam='\0'; break;}
else
if(nam==8)
{
if(i!=0)
{
printf("%c",8);
i--;
}
continue;
}
else
printf("*");
i++;
}


if(!strcmp(str,nam))
{
if(strlen(str)<13&&strlen(str)>3)
break;
else
printf("\n\n -the password has not changed !!");
printf("\n It must be from 4 to 12 letters !!\n");
}
else
printf("\n No match !!\n");
getch();
scrn();
}

set_pwf(str,0);
printf("\n\n -Your password has been changed and activated.\n");
getch();
scrn();
break;

case ('4'): //////////////////////////////// deactivate pw

i=pw_op(2);
if(i==1)
{
pw_op(3);
pw_op(2);
printf("\n -Your password deactivated.\n");
}
else
if(i==2)
{
pw_op(3);
printf("\n -Your password has been activated.\n");
}
getch();
scrn();
break;


case ('5'): endp();
default: printf("\nInvalid chois !\n");break;
}
}while(1);

}
// end main

////////////////// 13 , 8
//////////// , 7
//////////// , 10
/////////// , 9
//////////////// , 253 , 254 , 255 , 157 , 158

void rnd(FILE **codp)
{
struct timeb tm3;
//buf=&tm3;
double x,y=-1;
ftime(&tm3);
for(x=0;x<=(tm3.time-(tm3.time/100)*100);x++)
{
y=random(200)+(tm3.time-(tm3.time/100)*100)+s1;
if(y!=s1+s2)
fprintf(*codp,"%.0lf\t",y);
}

}

void INTtoBIN(int x,int*bin)
{
int j;
for(j=0;j<16;j++)
bin[j]=0;
j=0;
for(x;x>0;x/=2)
bin[j++]=x%2;
bin[++j]=(x/2);
}
////////////////////
void toggle(int *y)
{
if(*y==s1)
*y=s2;
else
if(*y==s2)
*y=s1;
else
printf("\n\n\tERROR");
}

int check_f_n(char nam[30],int x)
{
int i;
switch(x)
{
case(1):
for(i=0;nam!='\0';i++)
if(nam=='.')
return 0;
strcat(nam,".txt");
return 0;

case(2):
for(i=0;nam!='\0';i++)
if(nam=='.')
{
nam='\0';
return 0;
}
return 0;

default:
printf("\n\tERROR\n");
return 1;
}
}

void pwait(void)
{
char p[8]={'|','//','-','\\','|','//','-','\\'};
struct timeb tm1,tm2;
ftime(&tm1);
for (int i=0;;i++)
{if(i==8) i=0;
printf("%c",p);
ftime(&tm2);
printf("%c",8);
if(labs(tm2.time-tm1.time)>=4) break;
}
}


void scrn(void)
{
clrscr();
printf("\n\t ** Sudan University for Science and Technology **\n\n");
printf(" \n");
printf("\t\t\t+- MY TEXT ENCODER -+\n\n");
printf(" Created by : Ahmed \n");

printf(" -----------------------------------------------------------------");
}

void endp(void)
{
scrn();
printf("\n\n\n\t *+-- Thank you for using MY TEXT INCODER --+*");
getch();
abort();
}

int get_pw(char pw[12])
{
char upw[24];
int i;

printf("\n\n Enter the password : ");
for(i=0;;)
{
upw=getch();
if(upw==13)
{upw='\0'; break;}
else
if(upw==8)
{
if(i!=0)
{
printf("%c",8);
i--;
}
continue;
}
else
printf("*");
i++;
}

return !strcmp(pw,upw);
}

void set_pwf(char pw[12] ,int n)
{
FILE* fff=fopen(setup_f,"w+");
fprintf(fff,"%d ",n+s3);
fprintf(fff,"%d ",strlen(pw));
for(int i=0;i<strlen(pw);i++)
fprintf(fff,"%d ",pw+s3);
ftime(&tm);
fprintf(fff,"%ld ",tm.time);
fclose(fff);
}


int pw_op(int chos)
{
FILE *sorce;
int n=0,i,x;
long t;
char pw[12]="111111111111";


sorce=fopen(setup_f,"r+");
fscanf(sorce,"%d",&n);
n=n-s3;

fscanf(sorce,"%d",&x);
pw[x]='\0';

for(i=0;pw!='\0';i++)
{
fscanf(sorce,"%d",&x);
pw=x-s3;
}

fscanf(sorce,"%ld",&t);
fclose(sorce);
ftime(&tm);
if(chos==2)
{
if(n==-1)
{
set_pwf(pw,0);
return 2;
}
else
if(n==0)
set_pwf(pw,-1);
return 1;
}
if(n==-1&&chos!=3)
return 1;


if(n==err3)
{
clrscr();
exit(0);
}
if(n&&(n<err2)&&!(n%err)&&(tm.time-t<stop_t))
{
printf("\n -Sorry !!\n You can not use this program at this time\n");
//cout<<(tm.time-t);
exit(0);
}

do
{
if(n>err3-1)
printf("\n -LAST WARNNING !!\n If you enter the password uncorrect one more time \n (( this program will not run again ))\n");
else
if(n>err2-1&&chos==0)
printf("\n -WARNNING !!\n If you enter the password uncorrect one more time \n (( Your code file will be erased ))\n");
else
if(n%err==err-1)
printf("\n -WARNNING !!\n If you enter the password uncorrect one more time \n the program will not work for %0.2f hours\n",stop_t/(60*60));
if(!get_pw(pw)) // if password is not correct ( zero returned )
{
if(n==-1) n=0;
printf("\nthe password is not correct\n");
n++;
set_pwf(pw,n);
}
else
{
// printf("\n\t\t\t#*#*#*#*#*#*#*#*#*#*#*#*#*#*#\n");
n=0;
break;
}
if(n>err2&&chos==0)
return 0; // erase

}while(n%err);


if(n)
{
printf("\n -Sorry !!\n The program will not work for %0.2f hours\n",stop_t/(60*60));
ftime(&tm);
t=tm.time;
set_pwf(pw,n);
getch();
abort();
}

set_pwf(pw,n);

return 1;
}
</font><font size="4">

البرنامج طويييييل لو عندكم اي اختصارات او اقتراحات ممكن تطرحوها

وشكرا على وقتكم الثمين

وفي انتظار التعليقات

#2

ولو في احد عنده اي استفسار عن اي جزء في البرنامج هذا ايميلي

qadory_a1@hotmail.com

#3

ممتاز أخي برنامج جيد ومفيد :)

واصل تألقك

تحيات اخوك في الله

#4
اقتباس
ممتاز أخي برنامج جيد ومفيد

واصل تألقك

تحيات اخوك في الله

هل عمل لديك البرنامج ؟

---

وعليكم السلام ورحمة الله وبركاته , مبروك مقدما هذا البرنامج .. ولدي بعض الاسئلة أخي :

- ما خوارزمية التشفير التي استخدمت .. الفكرة على الاقل .

- البرنامج الاول setup .. يوجد به خطأ .. يبدو حصل أثناء نسخك للكود :

 for(i=0;i
   fprintf(sorce,"%d ",str+s3);

- البرنامج لايعمل الا بتعديلات في الفيجوال ستوديو , هناك الدالة random غير موجودة .. ولا اظنها قياسية .. استخدم rand , دائما استدعي ملفات iostream هكذا :

#include <iostream>

هناك خطأ يظهر لي .. لا أعرف ماهو

	 char pw[12]="111111111111";

error :
Error	56	error C2117: 'pw' : array bounds overflow	f:\incre\main.cpp	584

يمكن تصحيح هذا الخطأ بكتابة ..

 char pw[]={"111111111111"};

الدالة clrscr ليست قياسية على ما يبدو .. لذلك ابحث عن بديل لها .. أو قم بالغائها ..

هذه المشاكل ظهرت بعد تجربة البرنامج على مترجم visual c 2008 , والسبب هو عدم التقيّد بالدوال القياسية أثناء كتابة البرنامج .

- أتمنى أيضا ارفاق البرنامج كاملا في المرفقات وليس كمشاركة حتى لايبدو الموضوع كبيرا ... وقم بتحرير موضوعك حتى يظهر الموضوع بشكل جميل :) , أو يقوم بذلك احد المشرفين .

طبعا كل ما ذكرت للفائدة , وليس تصيّد للاخطاء , أعتقد هكذا يمكن أن نستفيد جميعا .

logo1.png تطبيق طمأنينة ، نسخة بيتا على أندرويد

عبدالله الشمّري - Al-Shammari

CodingAlone.com

twitter @abshammeri

abshammeri AT gmail.com

github : abshammeri

#5

السلام عليكــم ورحمـة الله وبركاتــة ،،

أشكرك يا اخي على الرد وتعليقاتك البناءة

وآسف على تأخري في الرد عليك لاني كنت في وقت امتحانات

بالنسبة للخطأ في الجملة الناقصة تعديله

fprintf(sorce,"%d ",strlen(str));
for(i=0;i<strlen(str);i++)		 ///////////////
fprintf(sorce,"%d ",str+s3);
ftime(&tm);

والخطا التالي

char pw[12]="111111111111";

error :
Error	56	error C2117: 'pw' : array bounds overflow	f:\incre\main.cpp	584

بسبب ان حجم السلسلة 12 وعدد عناصرها 12 فلا توجد مساحة لتخزبن '\0' في المصفوفة فيحدث

array bounds overflow

فالحل ممكن بالزيادة الى 13

البرنامج يعمل عندي ولكن بعض البرامج قد لا تعمل الا بالتعديل

انا اكتب في برنامج تربو سي بلس بلس

اما بالنسبة للدوال القياسية فلا اعرف الفرق بينها وبين غبرها أو اين تعمل :huh:

اما خوارزمية التشفير فساشرحها المرة القادمة ان شاء الله

حاولت ارفق الملف فظهرت رسالة

عملية إرفاق الملف فشلت, غير مسموح برفع هذا الملف

ساحاول في المرة القادمة الارفاق مرة اخرى

#6

الفكرة المستخدمة في التشفير :

أولا يقوم البرنامج بادراج عدد عشوائي من الاعداد العشوائية (في نسخة الملف المشفرة) حسب عامل زمني بالثواني

ثم يضع رقم معين يكون نهاية الاعداد العشوائية

هذا الرقم يكون قد منع وروده في الاعداد العشوائية

ثم يبدا تشفيرالنص الذي ساذكر طريقته لاحقا

بعد ان ينتهي من تشفير النص يدرج سلسلة من الارقام تدل على نهاية النص

ثم ايضا يدرج عدد عشوائي من الاعداد العشوائية

اما طريقة تشفير النص فتعتمد على رقمين اساسيين

يضاف الرقم الاول للحرف الاول والرقم الثاني للحرف الثاني ويضيف للحرف الثالث الرقم الاول والرابع الرقم الثاني وهكذا ( اقصد الاضافة للاسكي كود

حتى يصل لنهاية النص

عندي افكار اخرى لتعقيد الشفرة اكثر ساذكرها المرة القادمة ان شاء الله

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…