Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 773457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:58:05+00:00 2026-05-14T18:58:05+00:00

#include <iostream> #include <fstream> #include <cstring> using namespace std; typedef unsigned long int WORD;

  • 0
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

typedef unsigned long int WORD;  /* Should be 32-bit = 4 bytes        */
#define w         32             /* word size in bits                 */
#define r         12             /* number of rounds                  */
#define b         16             /* number of bytes in key            */
#define c          4             /* number words in key               */
                                 /* c = max(1,ceil(8*b/w))            */
#define t         26             /* size of table S = 2*(r+1) words   */
WORD S [t],L[c];                        /* expanded key table         */
WORD P = 0xb7e15163, Q = 0x9e3779b9;    /* magic constants            */
/* Rotation operators. x must be unsigned, to get logical right shift*/
#define ROTL(x,y) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1)))))
#define ROTR(x,y) (((x)>>(y&(w-1))) | ((x)<<(w-(y&(w-1)))))    

void RC5_DECRYPT(WORD *ct, WORD *pt) /* 2 WORD input ct/output pt     */
{
    WORD i, B = ct[1], A = ct[0];
    for (i = r; i > 0; i--)
    {
        B = ROTR(B - S[2 * i + 1], A)^A;
        A = ROTR(A - S[2 * i], B)^B;
    }
    pt[1] = B - S[1]; pt[0] = A - S[0];
}

void RC5_SETUP(unsigned char *K) /* secret input key K 0...b-1]       */
{
    WORD i, j, k, u = w/8, A, B, L[c];

    /* Initialize L, then S, then mix key into S */
    for (i = b - 1, L[c - 1] = 0; i != -1; i--) 
        L[i/u] = (L[i/u] << 8) + K[i];

    for (S[0] = P, i = 1; i < t; i++) 
        S[i] = S[i - 1] + Q;

    for (A=B=i=j=k=0; k<3*t; k++,i=(i+1)%t,j=(j+1)%c)      /* 3*t > 3*c */
    {
        A = S[i] = ROTL(S [i]+(A+B),3);
        B = L[j] = ROTL(L[j]+(A+B),(A+B));
    }
}

void printword(WORD A)
{
    WORD k;
    for (k=0 ;k<w; k+=8) 
        printf("%02.2lX",(A>>k)&0xFF);
}

int main()
{ 
    WORD i, j, k, pt [2], pt2 [2], ct [2] = {0,0};
    unsigned char key[b];
    ofstream out("cpt.txt");
    ifstream in("key.txt");

    if (!in)
    { 
        cout << "Cannot open file.\n"; 
        return 1; 
    }  

    if (!out)
    { 
        cout << "Cannot open file.\n"; 
        return 1; 
    }  

    key="111111000001111";

    RC5_SETUP(key);
    ct[0]=2185970173;
    ct[1]=3384368406;

    for (i=1; i<2; i++)
    {
         RC5_DECRYPT(ct,pt2);
         printf("\n   plaintext "); 
         printword(pt[0]); 
         printword(pt[1]);
    }

    return 0;
}

When I compile this code i get two warnings and also an error saying that I cant assign a char value to my character array. Why is that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:58:06+00:00Added an answer on May 14, 2026 at 6:58 pm

    Change:

    key="111111000001111";

    to

    strncpy((char *)key, "111111000001111", sizeof(key));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 429k
  • Answers 429k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Whether you stick to the Django packages that your distribution… May 15, 2026 at 1:38 pm
  • Editorial Team
    Editorial Team added an answer The reason I posted this question is because I couldn't… May 15, 2026 at 1:37 pm
  • Editorial Team
    Editorial Team added an answer If the arrays are this small, I would just do… May 15, 2026 at 1:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.