2013-05-26 28 views
0

。有问题的线路是阿达指数检查失败

End_String := End_String & Get_Character(
    S, Ind(Count*(length(Cipher_Text))/2), Ind(Count)); 

任何帮助将不胜感激。我正在使用Ada 95和一个GNAT编译器。

function Decipher(S : Square; Cipher_Text : Ustring) return Ustring is 

type IndArray is array(1..(length(Cipher_Text)*2)) of Integer; 

Ind : IndArray; 
Temp : Character; 
Row : Integer; 
Col : Integer; 
Count : Integer := 1; 
End_String : Ustring; 
begin 
    Ind := (others=>0); 
    for I in 1..length(Cipher_Text) loop 
     Temp := Uppercase(Element(Cipher_Text, I)); 
     if In_Square(S, Temp) then 
      Get_Coordinates(S, Temp, Row, Col); 
      Ind(I) := row; 
      Ind(I + length(Cipher_Text)) := Col; 
     end if; 
    end loop; 
    while Count <= length(Cipher_Text)*2 loop 
     End_String := End_String & Get_Character(
      S, Ind(Count*(length(Cipher_Text))/2), Ind(Count)); 
     Count := Count + 2; 
    end loop; 
    return End_String; 
end Decipher; 
+0

没有Ustring的声明,我们可能不会看到有什么问题。 –

+0

抱歉,我只是将Ustring声明为Unbounded_String,以便在规范文件中将其缩短。 – user2396120

回答

1

对于计数> 4表达

计数*(长度(Cipher_Text))/ 2

将超过您IndArray的大小。所以你的程序是错误的。由于您将行和列值长度(Cipher_Text)元素分开存储,因此您应该使用 长度(Cipher_Text)+计数等索引对其进行解码。

使用行和列作为字段的记录将删除所有 摆弄索引偏移,因为您可以将对(Row,Col)存储在 索引Count处。

+0

我实际上能够把它全部弄清楚!感谢您的帮助 – user2396120