所以我在Fortran 90中编写了一个基本的Vigenere Cypher,但是当我尝试编译它时,由于我的内部SUBROUTINES,我被不可分类的语句错误所打击。
我列出了每个SUBROUTINE中使用的变量'('')'但我仍然收到错误。我认为这是一个非常简单的解决方案,但我似乎无法找到解决方案。
这是我的代码:
PROGRAM Assign_8
IMPLICIT NONE
CHARACTER*750 :: Input
CHARACTER*10 :: Key
CHARACTER*750 :: RepeatedKey
CHARACTER*750 :: Encrypted, Decrypted
LOGICAL :: Path
CHARACTER*10 :: Validation
INTEGER :: Reps, Encrypt, Decrypt, KeyInt, InputInt, MergeInt, UnmergeInt
WRITE(*,*) 'Do you wish to Encrypt or Decrypt a file?'
CALL Validation_Sub
SUBROUTINE Validation_Sub(Path, Validation)
IMPLICIT NONE
READ(*,*) Validation
SELECT CASE (Validation)
CASE ('Encrypt' , 'encrypt')
WRITE(*,*) 'You have selected to Encrypt a file.'
Path = .TRUE.
CASE ('Decrypt' , 'decrypt')
WRITE(*,*) 'You have selected to Decrypt a file.'
Path = .FALSE.
CASE DEFAULT
WRITE(*,*) 'Selection not valid please select to either Encrypt or Decrypt a file.'
IF (Path .EQV. .TRUE.) THEN
CALL Encrypt_Sub
ELSE IF (Path .EQV. .FALSE.) THEN
CALL Decrypt_Sub
END IF
END SELECT
END SUBROUTINE
SUBROUTINE Encrypt_Sub(Input, Key, RepeatedKey, Encrypt, InputInt, KeyInt, MergeInt, Encrypted)
IMPLICIT NONE
OPEN(1,FILE='plaintext.txt')
READ(1,'(A)') Input
WRITE(*,*) 'Please Enter a Key Phrase of 10 Characters (Including Spaces and Punctuation)'
READ(*,*) Key
RepeatedKey = REPEAT(Key(1:10),75)
DO Encrypt = 1, LEN_TRIM(Input)
InputInt = IACHAR(Input(Encrypt:Encrypt))
KeyInt = IACHAR(RepeatedKey(Encrypt:Encrypt))
MergeInt = InputInt + (KeyInt - 32)
IF (MergeInt > 126) THEN
MergeInt = MergeInt - 94
END IF
Encrypted(Encrypt:Encrypt) = ACHAR(MergeInt)
END DO
OPEN(2,FILE='EncryptionTest.txt')
WRITE(2,'(A)') Encrypted
CLOSE(2)
END SUBROUTINE
SUBROUTINE Decrypt_Sub(Encrypted, Key, RepeatedKey, Decrypt, MergeInt, KeyInt, UnmergeInt, Decrypted)
IMPLICIT NONE
OPEN(1,FILE='EncryptionTest.txt')
READ(1,'(A)') Encrypted
CLOSE(1)
WRITE(*,*) 'Please Enter Your Key Phrase'
READ(*,'(A)') Key
RepeatedKey = REPEAT(Key(1:10),75)
DO Decrypt = 1, 750, 1
MergeInt = IACHAR(Encrypted(Decrypt:Decrypt))
KeyInt = IACHAR(RepeatedKey(Decrypt:Decrypt))
UnmergeInt = MergeInt - (KeyInt - 32)
IF (UnmergeInt < 32) THEN
UnmergeInt = UnmergeInt + 94
END IF
Decrypted(Decrypt:Decrypt) = ACHAR(UnmergeInt)
END DO
OPEN(2,FILE='DecryptionTest.txt')
WRITE(2,'(A)') Decrypted
CLOSE(2)
END SUBROUTINE
END PROGRAM Assign_8
我得到的具体错误是:
SUBROUTINE Validation_Sub(Path, Validation)
1
>Unclassifiable Statement at (1)
(间隔)
IMPLICIT NONE
1
>Unexpected IMPLICIT NONE statement at (1)
我怀疑IMPLICIT NONE错误是由于未正确定义SUBROUTINE。
END SUBROUTINE
1
>Expecting END Program statement at (1)
和以前一样,我怀疑这是因为尚未定义SUBROUTINE。
这些错误重演:
SUBROUTINE Encrypt_Sub
&安培;
SUBROUTINE Decrypt_Sub
如果有人确实在我的Vigenere Cypher代码中发现任何即时错误,我们将非常感谢任何帮助,如果您能毫无疑问地指出它们,也会非常感激。
答案 0 :(得分:1)
您在子程序之前缺少CONTAINS
。
将来学习模块,但现在使用CONTAINS
使这些子程序在主程序内部正确。
所以看起来应该是
PROGRAM Assign_8
...
CALL Validation_Sub
CONTAINS
SUBROUTINE Validation_Sub(Path, Validation)
END SUBROUTINE
...
END PROGRAM Assign_8
答案 1 :(得分:1)
除了顶部缺少“包含”之外,还有其他几件小事。 你的选择案例应该在默认情况下结束,if(Path ...在它之外。默认情况也应该停止程序。 您还没有关闭其中一个文件单元。
这是我编译的代码 $ gfortran -Og -std = f95 -Wall test.f90
PROGRAM Assign_8
IMPLICIT NONE
LOGICAL :: Path
CHARACTER(LEN=10) :: Validation
CHARACTER(LEN=750) :: Input
CHARACTER(LEN=10) :: Key
CHARACTER(LEN=750) :: RepeatedKey
CHARACTER(LEN=750) :: Encrypted, Decrypted
INTEGER :: Encrypt, Decrypt, KeyInt, InputInt, MergeInt, UnmergeInt
WRITE(*,*) 'Do you wish to Encrypt or Decrypt a file?'
CALL Validation_Sub
CONTAINS
SUBROUTINE Validation_Sub
IMPLICIT NONE
READ(*,*) Validation
SELECT CASE (Validation)
CASE ('Encrypt' , 'encrypt')
WRITE(*,*) 'You have selected to Encrypt a file.'
Path = .TRUE.
CASE ('Decrypt' , 'decrypt')
WRITE(*,*) 'You have selected to Decrypt a file.'
Path = .FALSE.
CASE DEFAULT
WRITE(*,*) 'Selection not valid please select to either Encrypt or Decrypt a file.'
stop
end SELECT
IF (Path .EQV. .TRUE.) THEN
CALL Encrypt_Sub
ELSE IF (Path .EQV. .FALSE.) THEN
CALL Decrypt_Sub
END IF
END SUBROUTINE Validation_Sub
SUBROUTINE Encrypt_Sub
IMPLICIT NONE
OPEN(1,FILE='plaintext.txt')
READ(1,'(A)') Input
close(1)
WRITE(*,*) 'Please Enter a Key Phrase of 10 Characters (Including Spaces and Punctuation)'
READ(*,*) Key
RepeatedKey = REPEAT(Key,75)
DO Encrypt = 1, LEN_TRIM(Input)
InputInt = IACHAR(Input(Encrypt:Encrypt))
KeyInt = IACHAR(RepeatedKey(Encrypt:Encrypt))
MergeInt = InputInt + (KeyInt - 32)
IF (MergeInt > 126) THEN
MergeInt = MergeInt - 94
END IF
Encrypted(Encrypt:Encrypt) = ACHAR(MergeInt)
END DO
OPEN(2,FILE='EncryptionTest.txt')
WRITE(2,'(A)') Encrypted
CLOSE(2)
END SUBROUTINE Encrypt_Sub
SUBROUTINE Decrypt_Sub
IMPLICIT NONE
OPEN(1,FILE='EncryptionTest.txt')
READ(1,'(A)') Encrypted
CLOSE(1)
WRITE(*,*) 'Please Enter Your Key Phrase'
READ(*,'(A)') Key
RepeatedKey = REPEAT(Key,75)
DO Decrypt = 1, 750, 1
MergeInt = IACHAR(Encrypted(Decrypt:Decrypt))
KeyInt = IACHAR(RepeatedKey(Decrypt:Decrypt))
UnmergeInt = MergeInt - (KeyInt - 32)
IF (UnmergeInt < 32) THEN
UnmergeInt = UnmergeInt + 94
END IF
Decrypted(Decrypt:Decrypt) = ACHAR(UnmergeInt)
END DO
OPEN(2,FILE='DecryptionTest.txt')
WRITE(2,'(A)') Decrypted
CLOSE(2)
END SUBROUTINE Decrypt_Sub
END PROGRAM Assign_8