Linux multi-threaded server-side programming learning muduo (five) echo case is interchangeable with ROT13 encryption

1, modify EchoServer :: onMessage (), to achieve invert case

  • Modify EchoServer :: onMessage ()
    After receiving msg conversion
  for(unsigned int i = 0;i<msg.size();++i){
	if(msg[i] >= 'a' && msg[i] <= 'z'){
		msg[i] = char(msg[i] - 'a' + 'A');		
		continue;}
	else if(msg[i] >= 'A' && msg[i] <= 'Z'){
		msg[i] = char(msg[i] - 'A' + 'a');		
		continue;}
   }

The source code shown in FIG.
Here Insert Picture Description

  • Run code validation
    run echo in a terminal program.
# cd bin
# ./echo

In a further run the command terminal

# telnet localhost 2007

Here Insert Picture Description

2, modify EchoServer :: onMessage (), to achieve ROT13 encryption

  for(unsigned int i = 0;i<msg.size();++i){
	if((msg[i] >= 'a' && msg[i] <= 'm')  || (msg[i] >= 'A' && msg[i] <= 'M')){
		msg[i] = char(msg[i]  + 13);		
		continue;}
	else if((msg[i] >= 'm' && msg[i] <= 'z') || (msg[i] >= 'M' && msg[i] <= 'Z')){
		msg[i] = char(msg[i]  - 13);		
		continue;}

Here Insert Picture Description

  • Run code validation
    run echo in a terminal program.
# cd bin
# ./echo

In a further run the command terminal

# telnet localhost 2007

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/YoungSusie/article/details/90408515