×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / A question to those DX who are proficiency in UNIX scripts
    Write a script to use the rot13 (rotate 13) algorithm to encrypt/decrypt a file. rot13 adds 13 to the letters (with wrap-around). So A-M convert to N-Z and N-Z convert to A-M. "Bat" would convert to "Nmg". The first parameter should be a file to convert if present. If not present convert stdin. The second parameter should be an output file name if present. If not the output should go to stdout.
    • Let me try ... BTW, "Bat" should be "Ong" not "Nmg" :)
      #!/bin/sh

      if [ "X$1" = "X" ]
      then
      INPUT="-"
      else INPUT=$1
      fi

      if [ "X$2" = "X" ]
      then
      OUTPUT=`tty`
      else OUTPUT="$2"
      fi

      cat $INPUT | tr [a-mn-zA-MN-Z] [n-za-mN-ZA-m] > $OUTPUT
      • 谢谢