我目前正在Arduino IDE上实现Misty Block Cipher,并且遇到了一个奇怪的问题。请记住,我还远没有一个能干的编码员。我从github页面上获取了代码,并在一个在线C编译器上进行了编译,它工作得很好,但是在Arduino中,输出超级混乱了。我尝试调试这两个代码并在代码中打印不同的状态,而且我知道它的混乱之处。
#### Importing DASH COMPONENTS ##############################################################################
#coding: utf-8
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from plotly import graph_objs as go # or
#import plotly.graph_objs as go
import ipywidgets as widgets
from scipy import special
import datetime #To allow displaying today's Date in upper right corner
import json
import pandas as pd
import os
from flask import Flask
import numpy as np
#### Preparing FLASK App ####################################################################################
server = Flask('my app')
#### SCATTER PLOT ##########################################################################################
dfb=pd.read_csv('final_test.csv', encoding="latin-1", infer_datetime_format=True, parse_dates=['date'], skipinitialspace=True)
trace1=go.Bar( #Trace Enrollment
x=pd.to_datetime(dfb['date']),
y=dfb.set_index('date').resample('M')["enrolled"].sum(),
#y=dfb.groupby('date').enrolled.sum(),
#mode='lines + markers',
name='Enrollment',
)
trace2=go.Bar( #Trace empty enrollment
x=pd.to_datetime(dfb['date']),
y=dfb[dfb['enrolled'].isnull()].sum(),
name='Not Answered',
#xaxis='Performance'
)
trace3=go.Bar( #Trace Rejection to Enrollment
x=pd.to_datetime(dfb['date']),
y=dfb[dfb['enrolled'] == 2].sum(),
name='Rejected Participation',
#xaxis='Performance'
)
#### PERFORMANCE % ##########################################################################################
#############################################################################################################
#### CREATE STANDARD TABLES OF OUTPUT #########################################################################
def make_dash_table(df):
''' Return a dash definitio of an HTML table for a Pandas dataframe '''
table = []
for index, row in df.iterrows():
html_row = []
for i in range(len(row)):
html_row.append(html.Td([row[i]]))
table.append(html.Tr(html_row))
return table
#############################################################################################################
app = dash.Dash()
# Describe the layout, or the UI, of the app
app.layout = html.Div([
html.Div([ # page 1
html.A(['Print PDF'],
className="button no-print",
style={'position': "absolute", 'top': '-40', 'right': '0'}),
html.Div([ # subpage 1
# Row 1 (Header)
html.Div([
html.Div([
html.H5(
'An Example of DashBoard in Dash from Plotly'),
html.H6('Summary',
style={'color': '#7F90AC'}),
], className="nine columns padded"),
html.Div([
html.H1(
#[html.Span('03', style={'opacity': '0.5'}), html.Span('17')]),
datetime.datetime.now().strftime('%Y-%m-%d'), style={'opacity': '1','color': 'white', 'fontSize': 12}),
html.H1(datetime.datetime.now().strftime('%H:%M:%S'), style={'font-family': 'Times New Roman','opacity': '0.5','color': 'white', 'fontSize': 12}),
html.H6('Daily Updates')
], className="three columns gs-header gs-accent-header padded", style={'float': 'right'}),
], className="row gs-header gs-text-header"),
html.Br([]),
# Row 2
html.Div([
html.Div([
html.H6('Resume',
className="gs-header gs-text-header padded"),
], className="four columns"),
html.Div([
html.Div(children=[
html.H6(["Performance"],
className="gs-header gs-table-header padded"),
dcc.Graph(
id='example-graph',
figure={
'data': [trace1, trace2, trace3],
'layout':
go.Layout(
title='', width="508", height="300", legend=dict(x=0, y=7),
margin={'l': 20, 'b': 40, 't': 10, 'r': 65},
font=dict(
family='sans-serif',
size=8,
color='#000'
),
plot_bgcolor='#D9E0EC',
xaxis=dict(
title='',
tickangle=45,
ticklen=5,
#zeroline=False,
gridwidth=2,
showticklabels=True,
nticks=6,
),
yaxis=dict(
title='',
ticklen=5,
gridwidth=4,
),
)#, barmode='stack')
})
]),
], className="eight columns"),
], className="row "),
], className="subpage"),
], className="page"),
])
if 'DYNO' in os.environ:
app.scripts.append_script({
'external_url': 'https://cdn.rawgit.com/chriddyp/ca0d8f02a1659981a0ea7f013a378bbd/raw/e79f3f789517deec58f41251f7dbb6bee72c44ab/plotly_ga.js'
})
external_css = ["https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css",
"//fonts.googleapis.com/css?family=Raleway:400,300,600",
"https://cdn.rawgit.com/plotly/dash-app-stylesheets/5047eb29e4afe01b45b27b1d2f7deda2a942311a/goldman-sachs-report.css",
"https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"]
for css in external_css:
app.css.append_css({"external_url": css})
external_js = ["https://code.jquery.com/jquery-3.2.1.min.js",
"https://cdn.rawgit.com/plotly/dash-app-stylesheets/a3401de132a6d0b652ba11548736b1d1e80aa10d/dash-goldman-sachs-report-js.js"]
for js in external_js:
app.scripts.append_script({"external_url": js})
if __name__ == '__main__':
app.server.run()
在C编译器中打印以上代码即可得到
void misty1_encrypt(unsigned int *expkey, unsigned char *ptext,
unsigned char *ctext)
{
unsigned int D0, D1;
int i, j = 0;
for (i = 0; i < 32; i++) EK[i] = expkey[i];
D0 = D1 = 0;
for (i = 0; i < 4; i++) {
D0 = D0 << 8;
D0 |= ptext[j++];
}
printf("D0 atm:");
printf("%02x",D0);
printf("\n");
for (i = 0; i < 4; i++) {
D1 = D1 << 8;
D1 |= ptext[j++];
}
printf("D1 atm:");
printf("%02x",D1);
printf("\n");
}
但是,当在Arduino中打印代码时,这就是我得到的
old plaintext1 : 0123456789abcdef
D0 atm:1234567
D1 atm:89abcdef
我不想发布整个代码,所以它不需要20页,但是值得一提的是,我正在基于RFC2994实现来实现它,可以在这里找到:https://tools.ietf.org/html/rfc2994 >
根据我的少量编码知识,我认为此问题可能是由于使用Unsigned Int引起的,但是我使用了Uint_32t,并且得到了相同的输出。任何帮助将不胜感激。抱歉,如果帖子有点混乱,我会尽力回答可能有帮助的任何问题。