Prolog问题:变量和实例变量不统一,为什么?我该怎么做呢?

Prolog问题:变量和实例变量不统一,为什么?我该怎么做呢?,prolog,logic,gnu,Prolog,Logic,Gnu,好的,大家好 Prolog问题的问题域是加密协议 我有一个Prolog程序,我正试图在gnuprolog中运行。它应该有用…但当然不行 我想把要点放在这里: % two people, c (the client) and a (the attacker) % we have two public keys (asymmetric cryptographic keys, e.g.PGP) publicKey(k_c). publicKey(k_a). % we have two private

好的,大家好

Prolog问题的问题域是加密协议

我有一个Prolog程序,我正试图在gnuprolog中运行。它应该有用…但当然不行

我想把要点放在这里:

% two people, c (the client) and a (the attacker)
% we have two public keys (asymmetric cryptographic keys, e.g.PGP)
publicKey(k_c).
publicKey(k_a).
% we have two private keys (asymmetric cryptographic keys, e.g.PGP)
privateKey(k_a-1).
privateKey(k_c-1).
% here I define the two public/private key pairs.
keyPair(k_c,k_c-1).
keyPair(k_a,k_a-1).
% just some kind of id
id(c).
id(a).
% nonces (some kind of value that's always new and is not guessable)
nonce(n_c).
nonce(n_a).
% two functions
% enc(Data, Key) encrypts Data with Key
cryptoFunction(enc(_,_)).
% sign(Data, Key) signs Data with Key (a signature)
cryptoFunction(sign(_,_)).

% a default message sent from the client to a server
init(n_c,k_c,sign([c,k_c],k_c-1)).

% Now I want to find out all combinations that can be sent without violating the rules
% The server always checks for some kind of guard (see below)

% define the message template
init(Init_1, Init_2, Init_3) :-
% define the types
nonce(Init_1),
publicKey(Init_2),
id(Init_3_1_1),
% example:
% Init_3_1_2 means init
% third parameter of init (the sign function)
% first parameter of sign function
% second part of the concatenation
publicKey(Init_3_1_2),
privateKey(Init_3_2),
% build the message
Init_3 = sign(Init_3_1,Init_3_2),
Init_3_1 = [Init_3_1_1,Init_3_1_2],
keyPair(Init_2,SignKey).
Init_3 == sign([_,Init_2],SignKey).
主体的最后一条规则,“Init_3==sign([[uu,Init_2],SignKey)”是服务器正在检查的保护

现在,当我使用Prolog进行跟踪时,最后一部分被实例化为

sign([c,k_c],k_c-1) == sign([_281,k_c],k_c-1)
然后失败了。为什么281不实例化为c?其他一切都好。我必须使用Init_3_1_1作为变量名吗?还是有其他方法可以使用防护装置


我希望我能很好地解释这个问题,如果没有,请告诉我。

统一是内置谓词(=)/2,而不是(=)/2。例如:

?- sign([c,k_c],k_c-1) = sign([_281,k_c],k_c-1).
_281 = c.

该死,在使用equality之前,我尝试过统一,但跟踪似乎总是使用不同的私钥循环。它从未在跟踪中显示“试图实现最后一条规则”…但似乎只有在规则为真时才会显示。。。我的意思是跟踪没有显示“失败:守卫规则”。