from Custom import CustomBase import API import hashlib class SHA256 (CustomBase): stack = None def __init__(self, stack): self.stack = stack # __init__ def help(self): msg = "SHA1\n" msg += "----\n\n" msg += "Takes r0 from the stack\n\n" msg += "Calculates the SHA1 hash of r0\n\n" msg += "Pushes the result to r0" API.showPopup('Custom function', msg, font=('Courier',API.helpFontSize)) # help def calculate(self): if self.stack.inputMode != 'TEXT': API.toast('This operation is only supported in TEXT mode') return if self.stack.finishEntry() == -1: return # abort here because data in input line is invalid if self.stack.size() < 1: API.toast('This operation needs 1 argument') return r0 = self.stack.getRegister(0) self.stack.pop(1) m = hashlib.sha256() m.update(bytes(r0, 'utf-8')) self.stack.push(m.hexdigest()) # calculate # SHA256