program cipher
!This example shows use of encrypt, decrypt, and solve
implicit none
character(len = 50) :: inpt
integer :: shift
print *,'What string do you want to cipher?'
inpt = "abc"
print *,'What is the shift amount?'
read *, shift
print *, 'The encrypted word is '
call encrypt(inpt, shift)
print *, 'The encrypted word decrypted '
call decrypt(inpt, shift)
print *, 'Displaying all of the possible permutations of the input '
call encrypt(inpt, shift)
call solve(inpt, 26)
end program cipher
subroutine encrypt(inpt, shift)
implicit none
character(len = *) :: inpt
integer :: shift
integer :: i
integer :: length
character(len = 50) :: outpt
character :: temp
length = 3
do i=0, length
IF (IACHAR(inpt(i)) >= IACHAR("a") .AND. IACHAR(inpt(i)) <= IACHAR("z") ) THEN
temp = ACHAR( IACHAR(inpt(i)) - 32 )
ELSE
temp = ACHAR( IACHAR(inpt(i)) )
END IF
temp = ACHAR(MODULO((IACHAR(temp) + shift - IACHAR("A")), 26) + IACHAR("A"))
outpt = outpt//temp
print *, outpt
end do
print *, outpt
end subroutine encrypt
subroutine decrypt(inpt, shift)
implicit none
character(len = *) :: inpt
integer :: shift
integer :: i
integer :: length
character(len = 50) :: outpt
character temp
length = 3
do i=0, length
IF (IACHAR(inpt(i)) >= IACHAR("a") .AND. IACHAR(inpt(i)) <= IACHAR("z") ) THEN
temp = ACHAR( IACHAR(inpt(i)) - 32 )
ELSE
temp = ACHAR( IACHAR(inpt(i)) )
END IF
temp = ACHAR(MODULO((IACHAR(temp) - shift - IACHAR("A")), 26) + IACHAR("A"))
outpt = outpt//temp
print *, outpt
end do
print *, outpt
end subroutine decrypt
subroutine solve(inpt, shift)
implicit none
character(len = 50) :: inpt
integer :: shift
integer :: i
character(50) :: outpt
character :: temp
do i=0, shift
temp = ACHAR(IACHAR(inpt(i)) + shift)
outpt = outpt//temp
print *, outpt
end do
end subroutine solve