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

发布于 2024-10-24 03:17:26 字数 1789 浏览 5 评论 0原文

好啦,大家好!

我的 Prolog 问题的问题领域是加密协议。

我有一个 Prolog 程序,我想在 GNU Prolog 中运行。它应该有效...但当然不行。

我试图将其要点放在这里:

% 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([_,Init_2],SignKey)”是服务器正在检查的守卫。

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

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

然后失败。为什么_281不实例化为c?其他一切都还好。我必须使用 Init_3_1_1 作为变量名吗?或者还有其他方法可以使用守卫吗?

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

Okay, hello everyone!

The problem domain for my Prolog problem is cryptographic protocols.

I've a Prolog program I'm trying to run in GNU Prolog. It should work...but of course it doesn't.

I'm trying to put the gist of it here:

% 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).

The last rule of the body, "Init_3 == sign([_,Init_2],SignKey)" is the guard that the server is checking.

Now when I trace with Prolog, the last part is instantiated to

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

And then fails. Why doesn't _281 instantiate to c? Everything else is okay. Do I have to use Init_3_1_1 as the variable name? Or is there another way to be able to use the guard?

I hope I explained the problem well, if not, please do tell.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ヅ她的身影、若隐若现 2024-10-31 03:17:26

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

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

Unification is the built-in predicate (=)/2, not (==)/2. Example:

?- sign([c,k_c],k_c-1) = sign([_281,k_c],k_c-1).
_281 = c.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文