C Program to Perform ROT47 Cipher

in #programming5 years ago

The ROT47 Cipher can be implemented in the following C/C++ Function. The ROT47 Cipher helps to encode/decode plain-text.

#include <stdio.h>
#include <string.h>
 
void rot47(char *buf, int l) {
    for (int i = 0; i < l; ++ i) {
        if (buf[i] >= 33 && buf[i] <= 126) {
            buf[i] = 33 + ((buf[i] + 14) % 94);
        }
    }
}
 
int main(int argc, char* argv[]) {
    if (argc == 0) {
        return 0;
    }
    for (int i = 1; i < argc; ++ i) {
        rot47(argv[i], strlen(argv[i]));
        printf("%s\n", argv[i]);
    }
    return 0;
}

We can compile using gcc compiler:

$ ./gcc rot47.c -o rot47

Then, we can perform the ROT47 Cipher on the command line parameters:

$ ./rot47 "Hello, World" "How Are You!"
w6==@[ (@C=5
w@H pC6 *@FP

The same text ROT47-ed twice will revert to original text.

$ ./rot47 "w6==@[ (@C=5" "w@H pC6 *@FP"
Hello, World
How Are You!

--EOF (The Ultimate Computing & Technology Blog) --

Reposted to Blog

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^

NEW! Following my Trail (Upvote or/and Downvote)

Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com

My contributions

Delegation Service

Important Update of Delegation Service!

  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
  2. Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
  3. Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
    Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses

Sort:  

cryptography programming is also my hobby. My first encryption program was written in VB6 using aes rijndael algorithm.

However, plz sir check my today's post. I'm an active delegator (66K) & set @justyy as my witness proxy. I didn't get upvote from your trail -

https://steemit.com/hive-129948/@rme/steemit

Thanks. voted here.

thank you :)

Hey @justyy!

Im reaching to you to inform that now the Latino Community have a Witness Node (@cotina)

I'm falling in love with your work, Im a developer too, always commited to improve the things automating tasks. I will make sure to always offer the best to Steemit and our blockchain ;)

Im the community manager there,

Thank you @alejos7ven.

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.082
BTC 59780.31
ETH 1576.77
USDT 1.00
SBD 0.42