Click here to Skip to main content
14,326,871 members

Managed C++/CLI

 
Questionsingly linked list Pin
Member 1306030217-Jul-17 23:27
memberMember 1306030217-Jul-17 23:27 
AnswerRe: singly linked list Pin
Richard MacCutchan18-Jul-17 2:10
protectorRichard MacCutchan18-Jul-17 2:10 
GeneralRe: singly linked list Pin
Member 1306030218-Jul-17 15:14
memberMember 1306030218-Jul-17 15:14 
GeneralRe: singly linked list Pin
Richard MacCutchan18-Jul-17 20:43
protectorRichard MacCutchan18-Jul-17 20:43 
GeneralRe: singly linked list Pin
Member 1306030218-Jul-17 21:13
memberMember 1306030218-Jul-17 21:13 
GeneralRe: singly linked list Pin
Richard MacCutchan18-Jul-17 21:41
protectorRichard MacCutchan18-Jul-17 21:41 
GeneralRe: singly linked list Pin
Member 1306030218-Jul-17 21:45
memberMember 1306030218-Jul-17 21:45 
QuestionStuck with one program. Pin
B.Sudhir25-Jun-17 16:58
memberB.Sudhir25-Jun-17 16:58 
I was praciticing an exercise in the book called C How to program by deitel. In which a question is there about cryptography.
Following is the question (Also notice to the phrase mentioned in BOLD letters).
Quote:
(Enforcing Privacy with Cryptography) The explosive growth of Internet communications and data storage on Internet-connected computers has greatly increased privacy concerns. The field of cryptography is concerned with coding data to make it difficult (and hopefully—with the most advanced schemes—impossible) for unauthorized users to read. In this exercise you’ll investigate a simple scheme for encrypting and decrypting data. A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Write a separate application that inputs an encrypted four-digit integer and decrypts it (by reversing the encryption scheme) to form the original number. [Optional reading project: Research “public key cryptography” in general and the PGP (Pretty Good Privacy) specific public key scheme. You may also want to investigate the RSA scheme, which is widely used in industrial-strength applications.]


Following is the code block I've written for Encryption Scheme.

#include<stdio.h>

void main(){
    int iFirst;
    int iSecond;
    int iThird;
    int iFourth;
    int iTemp;

    printf("\nEnter four digits (with a space in between): ");
    scanf("%d %d %d %d", &iFirst, &iSecond, &iThird, &iFourth);

    iFirst = iFirst + 7;
    iSecond = iSecond + 7;
    iThird = iThird + 7;
    iFourth = iFourth + 7;

    iFirst = iFirst % 10;
    iSecond = iSecond % 10;
    iThird = iThird % 10;
    iFourth = iFourth % 10;

    //Swapping First <--> Third & Second <--> Fourth

    iTemp = iFirst;
    iFirst = iThird;
    iThird = iTemp;

    iTemp = iSecond;
    iSecond = iFourth;
    iFourth = iTemp;

    printf("\nEncrypted Data - %d%d%d%d", iFirst, iSecond, iThird, iFourth);
}


Output -
Quote:
Enter four digits (with a space in between): 1 2 3 4
1 2 3 4

Encrypted Data - 0189


and Decryption Scheme -

#include<stdio.h>

void main(){
    int iFirst;
    int iSecond;
    int iThird;
    int iFourth;
    int iTemp;

    printf("\nEnter encrypted four digits (with a space in between): ");
    scanf("%d %d %d %d", &iFirst, &iSecond, &iThird, &iFourth);

    iTemp = iFirst;
    iFirst = iThird;
    iThird = iTemp;

    iTemp = iSecond;
    iSecond = iFourth;
    iFourth = iTemp;

    iFirst = iFirst % 10;
    iSecond = iSecond % 10;
    iThird = iThird % 10;
    iFourth = iFourth % 10;

    iFirst = iFirst + 7;
    iSecond = iSecond + 7;
    iThird = iThird + 7;
    iFourth = iFourth + 7;



    //Swapping First <--> Third & Second <--> Fourth



    printf("\nDecrypted Data - %d%d%d%d", iFirst, iSecond, iThird, iFourth);
}


Output-
Quote:
Enter encrypted four digits (with a space in between)Blush | :O 1 8 9
0 1 8 9

Decrypted Data - 151678



Above programs should be working like this - if Encryption programs output for input 1234 is 0189 then Decryption program's output for input0189 should be 1234 but its not happening not sure why.

Can anyone help on this?
AnswerRe: Stuck with one program. Pin
Jochen Arndt25-Jun-17 21:40
mveJochen Arndt25-Jun-17 21:40 
GeneralRe: Stuck with one program. Pin
B.Sudhir25-Jun-17 22:14
memberB.Sudhir25-Jun-17 22:14 
AnswerRe: Stuck with one program. Pin
Artur Linov IT25-Jul-17 6:43
memberArtur Linov IT25-Jul-17 6:43 
Questionprinting the customized data through printer in vc++ 6.0 dialog based. Pin
Member 1322408614-Jun-17 19:42
memberMember 1322408614-Jun-17 19:42 
AnswerRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan14-Jun-17 22:50
protectorRichard MacCutchan14-Jun-17 22:50 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
rahul199514-Jun-17 23:20
memberrahul199514-Jun-17 23:20 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan15-Jun-17 1:04
protectorRichard MacCutchan15-Jun-17 1:04 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
rahul199515-Jun-17 2:27
memberrahul199515-Jun-17 2:27 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan15-Jun-17 2:57
protectorRichard MacCutchan15-Jun-17 2:57 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan15-Jun-17 3:06
protectorRichard MacCutchan15-Jun-17 3:06 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan15-Jun-17 6:15
protectorRichard MacCutchan15-Jun-17 6:15 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
rahul199515-Jun-17 20:15
memberrahul199515-Jun-17 20:15 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan15-Jun-17 21:26
protectorRichard MacCutchan15-Jun-17 21:26 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
rahul199515-Jun-17 21:46
memberrahul199515-Jun-17 21:46 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan15-Jun-17 21:53
protectorRichard MacCutchan15-Jun-17 21:53 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
rahul199516-Jun-17 0:09
memberrahul199516-Jun-17 0:09 
GeneralRe: printing the customized data through printer in vc++ 6.0 dialog based. Pin
Richard MacCutchan16-Jun-17 2:45
protectorRichard MacCutchan16-Jun-17 2:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.