def compute_session_key(self, salt, server_B): '''Calculates client's session key and evidence message.''' self.session_key = compute_hash(self.premaster_secret) self.M = compute_M(self.g, self.N, self.username, salt, self.A, server_B, self.session_key) self.hashed_AMK = compute_hash(self.A, self.M, self.session_key) return self.M
def apply_torque(self, u, dt=None): if dt is None: dt = self.dt C2 = np.cos(self.theta[1][0]) S2 = np.sin(self.theta[1][0]) M11 = (self.K1 + self.K2 * C2) M12 = (self.K3 + self.K4 * C2) M21 = M12 M22 = self.K3 H1 = (-self.K2 * S2 * self.dtheta[0][0] * self.dtheta[1][0] - 1 / 2.0 * self.K2 * S2 * self.dtheta[1][0]**2.0) H2 = 1. / 2. * self.K2 * S2 * self.dtheta[0][0]**2.0 ddq1 = ((H2 * M11 - H1 * M21 - M11 * u[1][0] + M21 * u[0][0]) / (M12**2.0 - M11 * M22)) ddq0 = (-H2 + u[1][0] - M22 * ddq1) / M21 M = utils.compute_M(self.alpha, self.beta, self.delta, self.theta) C = utils.compute_C(self.alpha, self.beta, self.delta, self.theta, self.dtheta) ddtheta = utils.fwd_dynamics(M, C, u, self.dtheta) print ddtheta print np.array([[ddtheta[0][0]], [ddtheta[1][1]]]) self.dtheta += np.array([[ddtheta[0][0]], [ddtheta[1][1]]]) * dt self.theta += self.dtheta * dt #self.dtheta += np.array([[ddq0], [ddq1]]) * dt #self.theta += self.dtheta * dt # move to next timestep self.t += dt
def compute_session_key(self, username, salt, client_A): ''' Calculates server's session key and evidence message. M = H(H(N) XOR H(g) | H(U) | s | A | B | K) H(A | M | K) ''' self.session_key = compute_hash(self.premaster_secret) self.M = compute_M(self.g, self.N, username, salt, client_A, self.B, self.session_key) self.hashed_AMK = compute_hash(client_A, self.M, self.session_key) return self.M
def __init__(self): # set up links and masses self.l1 = 1.0 self.l2 = 1.0 self.m1 = 1.5 self.m2 = 1.5 # set starting configuration self.theta[0] = 0.0 self.theta[1] = 0.0 # set dtheta as default 0 to begin with self.dtheta[0] = 0.0 self.dtheta[1] = 0.0 # set (x,y) ee and elbow position self.ee[0] = self.l1 * cos(self.theta[0]) self.ee[1] = self.l1 * sin(self.theta[0]) self.elbow[0] = self.ee[0] + self.l2 * cos(self.theta[0] + self.theta[1]) self.elbow[1] = self.ee[1] + self.l2 * sin(self.theta[0] + self.theta[1]) # compute constants self.alpha = self.m1 * self.l1**2 + self.m2 * (self.l1**2 + self.l2**2) self.beta = self.m2 * self.l1 * self.l2 self.delta = self.m2 * self.l2**2 # update M and C matrices given theta, dtheta information self.M = utils.compute_M(self.alpha, self.beta, self.delta, self.theta) self.C = utils.compute_C(self.alpha, self.beta, self.delta, self.theta, self.dtheta) self.t = 0.0 self.dt = 0.001 # compute non changing constants self.K1 = ((1 / 3.0 * self.m1 + self.m2) * self.l1**2.0 + 1 / 3.0 * self.m2 * self.l2**2.0) self.K2 = self.m2 * self.l1 * self.l2 self.K3 = 1 / 3.0 * self.m2 * self.l2**2.0 self.K4 = 1 / 2.0 * self.m2 * self.l1 * self.l2