public function runInteraction($aliceStore, $bobStore)
 {
     /*
     :type aliceStore: AxolotlStore
     :type  bobStore: AxolotlStore
     */
     $aliceSessionCipher = new SessionCipher($aliceStore, $aliceStore, $aliceStore, $aliceStore, self::BOB_RECIPIENT_ID, 1);
     $bobSessionCipher = new SessionCipher($bobStore, $bobStore, $bobStore, $bobStore, self::ALICE_RECIPIENT_ID, 1);
     $originalMessage = "smert ze smert";
     $aliceMessage = $aliceSessionCipher->encrypt($originalMessage);
     $this->assertTrue($aliceMessage->getType() == CiphertextMessage::WHISPER_TYPE);
     $plaintext = $bobSessionCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $aliceMessage->serialize()));
     $this->assertEquals($plaintext, $originalMessage);
     $bobMessage = $bobSessionCipher->encrypt($originalMessage);
     $this->assertTrue($bobMessage->getType() == CiphertextMessage::WHISPER_TYPE);
     $plaintext = $aliceSessionCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $bobMessage->serialize()));
     $this->assertEquals($plaintext, $originalMessage);
     for ($i = 0; $i < 10; $i++) {
         $loopingMessage = "What do we mean by saying that existence precedes essence? " . "We mean that man first of all exists, encounters himself, " . "surges up in the world--and defines himself aftward. " . $i;
         $aliceLoopingMessage = $aliceSessionCipher->encrypt($loopingMessage);
         $loopingPlaintext = $bobSessionCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $aliceLoopingMessage->serialize()));
         $this->assertEquals($loopingPlaintext, $loopingMessage);
     }
     for ($i = 0; $i < 10; $i++) {
         $loopingMessage = "What do we mean by saying that existence precedes essence? " . "We mean that man first of all exists, encounters himself, " . "surges up in the world--and defines himself aftward. " . $i;
         $bobLoopingMessage = $bobSessionCipher->encrypt($loopingMessage);
         $loopingPlaintext = $aliceSessionCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $bobLoopingMessage->serialize()));
         $this->assertEquals($loopingPlaintext, $loopingMessage);
     }
     $aliceOutOfOrderMessages = [];
     for ($i = 0; $i < 10; $i++) {
         $loopingMessage = "What do we mean by saying that existence precedes essence? " . "We mean that man first of all exists, encounters himself, " . "surges up in the world--and defines himself aftward. " . $i;
         $aliceLoopingMessage = $aliceSessionCipher->encrypt($loopingMessage);
         $aliceOutOfOrderMessages[] = [$loopingMessage, $aliceLoopingMessage];
     }
     for ($i = 0; $i < 10; $i++) {
         $loopingMessage = "What do we mean by saying that existence precedes essence? " . "We mean that man first of all exists, encounters himself, " . "surges up in the world--and defines himself aftward." . $i;
         $aliceLoopingMessage = $aliceSessionCipher->encrypt($loopingMessage);
         $loopingPlaintext = $bobSessionCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $aliceLoopingMessage->serialize()));
         $this->assertEquals($loopingPlaintext, $loopingMessage);
     }
     for ($i = 0; $i < 10; $i++) {
         $loopingMessage = "You can only desire based on what you know: " . $i;
         $bobLoopingMessage = $bobSessionCipher->encrypt($loopingMessage);
         $loopingPlaintext = $aliceSessionCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $bobLoopingMessage->serialize()));
         $this->assertEquals($loopingPlaintext, $loopingMessage);
     }
     foreach ($aliceOutOfOrderMessages as $aliceOutOfOrderMessage) {
         $outOfOrderPlaintext = $bobSessionCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $aliceOutOfOrderMessage[1]->serialize()));
         $this->assertEquals($outOfOrderPlaintext, $aliceOutOfOrderMessage[0]);
     }
 }
Esempio n. 2
0
 protected function runInteraction($aliceSessionRecord, $bobSessionRecord)
 {
     $aliceStore = new InMemoryAxolotlStore();
     $bobStore = new InMemoryAxolotlStore();
     $aliceStore->storeSession(2, 1, $aliceSessionRecord);
     $bobStore->storeSession(3, 1, $bobSessionRecord);
     $aliceCipher = new SessionCipher($aliceStore, $aliceStore, $aliceStore, $aliceStore, 2, 1);
     $bobCipher = new SessionCipher($bobStore, $bobStore, $bobStore, $bobStore, 3, 1);
     $alicePlaintext = 'This is a plaintext message.';
     $message = $aliceCipher->encrypt($alicePlaintext);
     $bobPlaintext = $bobCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $message->serialize()));
     $this->assertEquals($alicePlaintext, $bobPlaintext);
     $bobReply = 'This is a message from Bob.';
     $reply = $bobCipher->encrypt($bobReply);
     $receivedReply = $aliceCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $reply->serialize()));
     $this->assertEquals($bobReply, $receivedReply);
     $aliceCiphertextMessages = [];
     $alicePlaintextMessages = [];
     for ($i = 0; $i < 50; $i++) {
         $alicePlaintextMessages[] = 'смерть за смерть ' . $i;
         $aliceCiphertextMessages[] = $aliceCipher->encrypt("смерть за смерть {$i}");
     }
     //shuffle(aliceCiphertextMessages)
     //shuffle(alicePlaintextMessages)
     for ($i = 0; $i < count($aliceCiphertextMessages) / 2; $i++) {
         $receivedPlaintext = $bobCipher->decryptMsg(new WhisperMessage(null, null, null, null, null, null, null, null, $aliceCiphertextMessages[$i]->serialize()));
         $this->assertEquals($receivedPlaintext, $alicePlaintextMessages[$i]);
     }
 }