• Source
    1. program cipher
    2. !This example shows use of encrypt, decrypt, and solve
    3. implicit none
    4. character(len = 50) :: inpt
    5. integer :: shift
    6. print *,'What string do you want to cipher?'
    7. inpt = "abc"
    8. print *,'What is the shift amount?'
    9. read *, shift
    10. print *, 'The encrypted word is '
    11. call encrypt(inpt, shift)
    12. print *, 'The encrypted word decrypted '
    13. call decrypt(inpt, shift)
    14. print *, 'Displaying all of the possible permutations of the input '
    15. call encrypt(inpt, shift)
    16. call solve(inpt, 26)
    17. end program cipher
    18.  
    19. subroutine encrypt(inpt, shift)
    20. implicit none
    21. character(len = *) :: inpt
    22. integer :: shift
    23. integer :: i
    24. integer :: length
    25. character(len = 50) :: outpt
    26. character :: temp
    27. length = 3
    28. do i=0, length
    29. IF (IACHAR(inpt(i)) >= IACHAR("a") .AND. IACHAR(inpt(i)) <= IACHAR("z") ) THEN
    30. temp = ACHAR( IACHAR(inpt(i)) - 32 )
    31. ELSE
    32. temp = ACHAR( IACHAR(inpt(i)) )
    33. END IF
    34. temp = ACHAR(MODULO((IACHAR(temp) + shift - IACHAR("A")), 26) + IACHAR("A"))
    35. outpt = outpt//temp
    36. print *, outpt
    37. end do
    38. print *, outpt
    39. end subroutine encrypt
    40.  
    41. subroutine decrypt(inpt, shift)
    42. implicit none
    43. character(len = *) :: inpt
    44. integer :: shift
    45. integer :: i
    46. integer :: length
    47. character(len = 50) :: outpt
    48. character temp
    49. length = 3
    50. do i=0, length
    51. IF (IACHAR(inpt(i)) >= IACHAR("a") .AND. IACHAR(inpt(i)) <= IACHAR("z") ) THEN
    52. temp = ACHAR( IACHAR(inpt(i)) - 32 )
    53. ELSE
    54. temp = ACHAR( IACHAR(inpt(i)) )
    55. END IF
    56. temp = ACHAR(MODULO((IACHAR(temp) - shift - IACHAR("A")), 26) + IACHAR("A"))
    57. outpt = outpt//temp
    58. print *, outpt
    59. end do
    60. print *, outpt
    61. end subroutine decrypt
    62.  
    63. subroutine solve(inpt, shift)
    64. implicit none
    65. character(len = 50) :: inpt
    66. integer :: shift
    67. integer :: i
    68. character(50) :: outpt
    69. character :: temp
    70. do i=0, shift
    71. temp = ACHAR(IACHAR(inpt(i)) + shift)
    72. outpt = outpt//temp
    73. print *, outpt
    74. end do
    75. end subroutine solve