开发者

can we write rules for Cryptographic function

Can we write cryptographic function as rule in prolog i.e.

C = enc(K, M).
M = dec(K, C).

I don't want low level detail but want to write a functor which provide me this functionality. If it is not possible in prolog then can some one give me reas开发者_如何学Coning behind that due to this reason prolog doesn't support this kind of functions.


In ISO standard Prolog I don't believe you can, but SWI-Prolog has an extension that allows this. If you define predicates

enc(K, M, Result) :- % whatever
dev(K, C, Result) :- % whatever

that return a result in their third argument, you can say

:- arithmetic_function(enc/2).
:- arithmetic_function(dec/2).

and use those with

C is enc(K, M).

etc. You can't do this with =, because that has a special meaning in Prolog: unification of the variable C with the term (data structure) enc(K,M).


I don't know anything about functors, and prolog did't know about them too. You may use only predicates - facts, witch connect some variables.

For example

encode(+Key, +Message, -CodeMessage)/3
decode(+Key, +CodeMessage, -OriginalMessage)/3

It means, that only if you know key and message you could get code of this message with encode/3 predicate. And only if you know key and code of the message you could get the original message with decode/3 predicate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜