قسم لغات البرمجة php java c++ جافا Visual Basic فيجوال بيسك c# Delphi دلفي API PERL HTML و TML JavaScript ASP XML Oracle اوركال MySql sql server Access

أدوات الموضوع

allin
:: مهندس ::
تاريخ التسجيل: Feb 2011
المشاركات: 7
نشاط [ allin ]
قوة السمعة:0
قديم 19-02-2011, 03:13 PM المشاركة 1   
ha مطلوب مساعدة عاجلة من مبرمجين بلغة فيجوال سي++ Twitter FaceBook Google+



البرنامج الاول عبارة عن برنامج للتشفير ب otp لكن كيف يمكن ان اخذ المفتاح من الparallport ارجو من خبراء البرمجة مساعدتي في مشروع التخرج بكتابة الاكواد المعدلة



كود:
#include <iostream>            //Standard C++ I/O.  Used for debugging mainly.  Could be done away with.
#include <time.h>            //Allows a Cish way to seed the rand() function with the timer
#include <fstream>            //Standard file usage.

using namespace std;        //Standard Namespace.

typedef char filename[80];    //The path+filenames of the files used

//MACROS

//This is just a nice way to do a XOR operation in code.
#define xor ^

//This allows a specific random range of int values.  Another VisC++ copy-paste.
#define getrandom(min, max) \
    ((rand()%(int)(((max)+1)-(min)))+(min))

//BEGIN MAIN PROGRAM
int main()
{
    unsigned char CharSizedChunk;        //A char sized chunk of data.
    unsigned char keys;                    //The character that will make up the pad.

    //The file names
    filename InFileName = "";            //File to be encrypted
    filename EncryptName = "encrypted.dat";    //The encrypted file from the InFile
    filename PadName = "key.dat";        //The pad of keys to unencrypt the data

    fstream InFile, outPad, outEncrypt;    //The actual files.

    cout << "Please type in the name (and location) of the file you want to encrypt:\n ";
    cin  >> InFileName;

    try
    {
        //The file to encrypt
        InFile.open(InFileName,ios::in | ios::binary);        //Input from the file to encrypt
        if(!InFile)                 //Throws a Abort, Retry, Ignore error for the OS to take over
            throw cerr << "The File \"" << InFileName << '\"' << " Did Not Open!!!\n\n";    //Ends in error.

        //Pad info
        outPad.open(PadName,ios::out | ios::binary);            //Output to the pad file
        if(!outPad)                 //Throws a Abort, Retry, Ignore error for the OS to take over
            throw cerr << "The File \"" << PadName << '\"' << " Did Not Open!!!\n\n";        //Ends in error.

        //The encrypted file
        outEncrypt.open(EncryptName,ios::out | ios::binary);    //Output to an encypted version of the input file
        if(!outEncrypt)             //Throws a Abort, Retry, Ignore error for the OS to take over
            throw cerr << "The File \"" << EncryptName << '\"' << " Did Not Open!!!\n\n";    //Ends in error.
    }
    catch( ... )    //Arbitrary net
    {
        return (system("pause"));
    }
    InFile.seekg(0);            //Sets the filepointer to the begining of the file

//The Encryption stuff
    cout << "\n\n~Encrypting the Bytes~\n\n";    //An unnecessary title

    srand( (unsigned)time( NULL ) );    //Radomize using the computer's system timer as a seed value

    //Reads byte sized (ie ASCII character) chunks.  Literally reads the input file one char at a time.
    while( InFile.read((char *) & CharSizedChunk, sizeof (unsigned char)) )
    {
      //cout << CharSizedChunk;                        //More debugging output
        keys = unsigned char(getrandom(32,126));    //Makes the so called "pad."
        CharSizedChunk = CharSizedChunk ^ keys;        //XOR's the char with the randomly generated key.
      //cout << CharSizedChunk;                        //ECHOs the encrytion onto the screen; again debug usage
        outPad.write((char *) & keys, sizeof (unsigned char));    //Writes a char to the pad file
        outEncrypt.write((char *) & CharSizedChunk, sizeof (unsigned char));    //Writes a char to the encrypted file
    }

    //Closes the files out.
    outPad.close();outPad.clear();
    outEncrypt.close();outEncrypt.clear();
    InFile.close();InFile.clear();

    cout << "\n\nSome Helpful Hints ...\n"
         << "*Only use the pad generated once.\n"
         << "*Make sure you means of delivering the pad are secure!\n"
         << "*When you run the Unencryption Software ... all you need is the \"xxx.dat"
         << "\"\n and \"pad.dat\" to generate an \"out.dat\" file which is your Unencrypted file.\n\n";
    return (system("pause")); //return 0;
}
//END MAIN PROGRAM






البرنامج الثاني عبارة عن برنامج فك للتشفير ب otp لكن كيف يمكن ان اخذ المفتاح من الparallport ارجو من خبراء البرمجة مساعدتي

كود:
 #include <iostream>            //Standard C++ I/O.  Used for debugging.
#include <time.h>            //Allows a Cish way to seed the rand() function with the timer
#include <fstream>            //Standard file usage.

using namespace std;        //Standard Namespace.

typedef char filename[80];    //The path+filenames of the files used

//MACROS

//This is just a nice way to do a XOR operation in code.
#define xor ^

//BEGIN MAIN PROGRAM
int main()
{
    unsigned char CharSizedChunk;            //A char sized chunk of data.
    unsigned char keys;                        //The character that will make up the pad.

    //The file names
    filename OutFileName = "Decrypted.dat";        //File made from the encrypted file
    filename EncryptName = "Encrypted.dat";        //The encrypted file from the InFile
    filename PadName = "key.dat";            //The pad of keys to unencrypt the data

    fstream inPad, inEncrypt, outDecrypt;    //The actural file instances

    try
    {
        //Opens the One Time Pad file for input
        inPad.open(PadName,ios::in | ios::binary);        //Input from the pad file
        if(!inPad)        //Throws a Abort, Retry, Ignore error for the OS to take over
            throw cerr << "The File \"" << PadName << '\"' << " Did Not Open!!!\n\n";//Ends in error.

        //Opens the Encrypted file for input
        inEncrypt.open(EncryptName,ios::in | ios::binary);//Input from the encrypted file
        if(!inEncrypt)    //Throws a Abort, Retry, Ignore error for the OS to take over
            throw cerr << "The File \"" << EncryptName << '\"' << " Did Not Open!!!\n\n";//Ends in error.

        outDecrypt.open(OutFileName,ios::out | ios::binary);//The output file, decrypted
        if(!outDecrypt)    //Throws a Abort, Retry, Ignore error for the OS to take over
            throw cerr << "The File \"" << OutFileName << '\"' << " Did Not Open!!!\n\n";//Ends in error.
    }
    catch( ... )
    {
        return (system("pause")); //return 0;
    }

    inEncrypt.seekg(0);            //Sets the filepointer to the begining of the file
    inPad.seekg(0);                //Sets the filepointer to the begining of the file

//The Unencryption Half
    cout << "\n\n~Unencrypting the Bytes~\n\n";    //Another debugging title

    //Goes through the encrypted file, and the pad one char at a time.
    while(inEncrypt.read((char *) & CharSizedChunk, sizeof(unsigned char)) )
    {        
        //Reads the encryption
        inPad.read((char *) & keys, sizeof(unsigned char));

        //Unencrypts
        CharSizedChunk = CharSizedChunk ^ keys;

        //Final string writting
        // Kills the extra carrage returns ... an unusual symptom.  No doubt Visual C++.
        if( (int(CharSizedChunk) != 13) ) //Text editors fill in carrage returns at line feeds anyways
        {
          //cout << CharSizedChunk << ' ';    //ECHOs the decrytion onto the screen
            outDecrypt.write((char *) & CharSizedChunk, sizeof(unsigned char));
        }
    }

//Makes sure everything is closed out.
    inPad.close();inPad.clear();
    inEncrypt.close();inEncrypt.clear();
    outDecrypt.close();outDecrypt.clear();

    cout << "\n\n";
    return (system("pause")); //return 0;
}
//END MAIN PROGRAM

اعلانات

allin
:: مهندس ::
تاريخ التسجيل: Feb 2011
المشاركات: 7
نشاط [ allin ]
قوة السمعة:0
قديم 19-02-2011, 08:29 PM المشاركة 2   
افتراضي


اين الردود يا اعضاء و هل في مبرمج موهوب يحل مشكلتى

اعلانات اضافية ( قم بتسجيل الدخول لاخفائها )
  

الصورة الرمزية eissa4444
eissa4444
:: مهندس متواجد ::
تاريخ التسجيل: Nov 2009
الدولة: tanta
المشاركات: 115
نشاط [ eissa4444 ]
قوة السمعة:0
قديم 23-03-2011, 07:22 PM المشاركة 3   
افتراضي


- التوفيق خير قائد، وحسن الخلق خير قرين، والعقل خير صاحب، والأدب خير ميراث....الإمام علي ابن أبي طالب

إضافة رد

العلامات المرجعية

«     الموضوع السابق       الموضوع التالي    »
أدوات الموضوع

الانتقال السريع إلى


الساعة معتمدة بتوقيت جرينتش +3 الساعة الآن: 06:31 PM
موقع القرية الالكترونية غير مسؤول عن أي اتفاق تجاري أو تعاوني بين الأعضاء
فعلى كل شخص تحمل مسئولية نفسه إتجاه مايقوم به من بيع وشراء وإتفاق وأعطاء معلومات موقعه
التعليقات المنشورة لا تعبر عن رأي موقع القرية الالكترونية ولايتحمل الموقع أي مسؤولية قانونية حيال ذلك (ويتحمل كاتبها مسؤولية النشر)

Powered by vBulletin® Version 3.8.6, Copyright ©2000 - 2025