transmit_demo.py

Created by antarctus

Created on September 30, 2023

929 Bytes

Démonstration de communication asynchrone.


from random import *

def encode(txt,key):
  return "".join([chr((ord(c)-97+key)%26+97) for c in txt])

class Deck():
  def __init__(self):
    self.deck=["pikachu","tranchodon"]
    self.wait_sending=[]
    self.wait_reception=[]
    self.key=randint(0,25)

  def start_sending(self,pk):
    if pk in self.deck:
      self.wait_sending+=[pk]
      return encode(pk,self.key)

  def start_reception(self,msg):
    self.wait_reception+=[msg]
    return msg+"-"+encode(msg,self.key)

  def end_sending(self,msg):
    pk=encode(msg.split("-")[0],-self.key)
    if pk in self.wait_sending:
      self.wait_sending.remove(pk)
      self.deck.remove(pk)
      return msg.split("-")[0]+"-"+encode(msg.split("-")[1],-self.key)

  def end_reception(self,msg):
    pk_c=msg.split("-")[0]
    if pk_c in self.wait_reception:
      self.wait_reception.remove(pk_c)
      self.deck+=[encode(msg.split("-")[1],-self.key)]

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.