Tips for encrypting Linux Command-line text

Source: Internet
Author: User
Tags control characters decrypt

Tips for encrypting Linux Command-line text

I learned this method when I was learning Shell raiders, and it was simple and interesting, so I'm going to put it together and share it with you.

ROT13 Text Encoding Introduction

ROT13 (Rotary 13-bit, rotateby13places, sometimes a minus sign in the middle is called ROT-13) is a simple replacement cipher. It is generous to call ROT13 "Encryption", and "text obfuscation" is more accurate. Sometimes it is used to hide potentially offensive content in text.

Principle

Applying ROT13 to a piece of text only needs to check the character alphabetical order and replace it after 13 bits
The corresponding letter, the need to go back to the beginning of the 26 English letter. A change to N, b to O, and so on to M for z, and then sequence reversal: N to a, o to B, and finally z to M. Only these appear in English. Since the number of bits moved is half the possible 26 characters, the algorithm is executed again on the text, reverting to its original form.

Using the TR command at the command line

1. Function: TR command, its full name "text Replacer", the command is used for text substitution. Character conversions are performed from standard input through a replace or delete operation. TR is primarily used to remove control characters from a file or to convert characters.

2. Options:
-C replaces this character set with a complement to the character set in string 1, which requires the character set to be ASCII.
-d deletes all input characters in string 1.
-S Delete all occurrences of a sequence of characters, leaving only the first one; the string compression is about to recur to a string.

Instance
    1. Encryption:
    2. Decrypt:
Code implementation-specific code
/************************************************************************* > File name:rot13.c > Author: AnSwEr > Mail: [email protected] > Created time:2015 August 18 Tuesday 12:02 28 seconds *********************************** *************************************// * * Realize ROT13 by C */#include <stdio.h>#include <string.h>#define MAXSIZE 1024x768Char*ROT13 (Char*string,unsigned intLen) {Char*str =string;intI for(i =0; I < Len-1; i++) {if(Str[i] >=' A '&&str[i] <=' Z ') Str[i] =' A '+ (Str[i]-' A '+ -) % -;if(Str[i] >=' A '&&str[i] <=' Z ') Str[i] =' A '+ (Str[i]-' A '+ -) % -; }returnSTR;}intMainvoid){CharStr_old[maxsize];Char*str_new;unsigned intLengthprintf("Please input your string want to encrypt by rot13:\n"); Fgets (Str_old,sizeof(Str_old), stdin); Length =strlen(Str_old);/*encrypt*/STR_NEW=ROT13 (str_old,length);printf("After encrypt,string is:\n");fputs(Str_new,stdout);/*decrypt*/Length =strlen(str_new); STR_NEW=ROT13 (str_new,length);if(strcmp(str_new,str_old) = =0)printf("Decrypt successfully!\n");Else        printf("Decrypt failed!\n");printf("After decrypt,string is:\n");fputs(Str_new,stdout);return 0;}
Run

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Tips for encrypting Linux Command-line text

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.