def postMessage(message, to_uid):
    print(
        f"Posting message to {USERS[to_uid]['fname']} {USERS[to_uid]['lname']}..."
    )

    route = 'postMessage'
    url = f"{API}{route}&token={TOKEN}&uid={UID}"

    A = Crypto()
    A.load_keys(PUBKEYS[to_uid]['pubkey'])

    encrypted = A.encrypt(message)
    encrypted_bytes = base64.b64encode(encrypted)
    message = encrypted_bytes.decode('utf-8')

    payload = {
        'uid': UID,
        'to_uid': to_uid,
        'message': message,
        'token': TOKEN
    }

    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, headers=headers, json=payload)
    return r.json()
def getMessages(count=1, latest=True):
    """ Gets decrypted messages from the server. """

    print("Checking for new messages...")

    route = 'getMessage'
    url = f"{API}{route}&token={TOKEN}&uid={UID}&count={count}"
    r = requests.get(url)

    D = Crypto()
    D.load_keys(priv_file="my_private_key.txt")

    messages = r.json()
    messages = messages[
        'data']  # get all the messages received from other users

    for message in messages:
        fid, received = message['fid'], message[
            'message']  # grabs most recent message and user's id
        received_bytes = received.encode('utf-8')  # prepares message
        received = base64.decodebytes(received_bytes)  # for decryption

        try:
            decrypted = D.decrypt(received)  #decrypts message
            print(f"\nfrom: {USERS[fid]['fname']} {USERS[fid]['lname']}")
            print("message:", decrypted, '\n')
        except ValueError:
            print(f"\nfrom: {USERS[fid]['fname']} {USERS[fid]['lname']}")
            print("message:", received, '\n')
Beispiel #3
0
async def step_two(message: types.Message):
   fiat = message.text
   db_crypto = Crypto('sqlite.db', fiat)
   courses_arr = db_crypto.get_courses(fiat) 
   answer = f"""
   Bitcoin {courses_arr[0]}\n
   Litecoin {courses_arr[1]}\n
   Dash {courses_arr[2]}\n
   Ethereum {courses_arr[3]}\n
   Ethereum Classic {courses_arr[4]}\n
   Neo {courses_arr[5]}\n
   IOTA {courses_arr[6]}\n
   Bitcoin Cash {courses_arr[7]}"""
   await message.answer(answer)
Beispiel #4
0
def postMessage(message, to_uid):
    route = 'postMessage'
    url = f"{API}{route}&token={TOKEN}&uid={UID}"

    # to encrypt the message lets use the Crypto class
    C = Crypto()
    # to load the public key for encryption
    C.load_keys(KEYS[to_uid]['pubkey'])
    encryptedMessage = C.encrypt(message)
    # to make sure that text is in bytes format
    Byte_text = base64.b64encode(encryptedMessage)
    message = Byte_text.decode('utf-8')

    payload = {
        'uid': UID,
        'to_uid': to_uid,
        'message': message,
        'token': TOKEN
    }

    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, headers=headers, json=payload)
    return r.json()
"""
import requests
from crypto_class import Crypto
import sys
import json
import base64
from random import shuffle

# Used to create a menu interface
from consolemenu import *
from consolemenu.items import *
"""
 Its up to you to alter the Crypto class to store keys correctly 
 as well as use them to encrypt messages with the proper public key. 
"""
C = Crypto()
"""
 These two statemets generate keys and save them, but with hard
 coded values. Definitely needs changed up. 
"""
C.generate_keys()
C.store_keys()

BASEURL = "http://msubackend.xyz/api/"


def is_json(myjson):
    try:
        json_object = json.loads(myjson)
    except ValueError as e:
        return False
Beispiel #6
0
"""
https://requests.readthedocs.io/en/master/user/quickstart/
https://stackoverflow.com/questions/9168340/using-a-dictionary-to-select-function-to-execute
"""
import requests
from crypto_class import Crypto  # import the crypto class
import os
import sys

crypt_helper = Crypto()  # instance of crypto class


def generate_keys():
    r = requests.get('http://localhost:8080/public_key/02')
    print(r.text)


def message():
    m = input("Message:")
    p = requests.post('http://localhost:8080/message', json={"message": m})


def end_program():
    print("Great ... quitter.")
    sys.exit()


choice_functions = {
    "Generate Keys": generate_keys,
    "Message": message,
    "Quit": end_program
Beispiel #7
0
from aiogram.types import ReplyKeyboardRemove, \
    ReplyKeyboardMarkup, KeyboardButton, \
    InlineKeyboardMarkup, InlineKeyboardButton


# Configure logging

logging.basicConfig(level=logging.INFO)

#initialize the bot
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
fiatg = 'USD'
db_users = Subs('sqlite.db')
db_crypto = Crypto('sqlite.db',fiatg)

@dp.message_handler(commands=['start'])
async def step_one(message: types.Message):
    
    #This handler will be called when user sends `/start`  command
    
    
    await message.answer("""Hello, My name is CryptoWatch

You can get the latest cryptocurrency exchange rate, just type /start to begin.

You can also subscribe to a particular crypto price (get a trade signal), for example: “23000 < BTC” (number > or < Ticker).

 I will remind you when the price reaches the set value.