Skip to content

Instantly share code, notes, and snippets.

@MariaMelnik
Created November 22, 2018 11:41
Show Gist options
  • Save MariaMelnik/d1e6fe2371d6fa55521baef2bf6e22d9 to your computer and use it in GitHub Desktop.
Save MariaMelnik/d1e6fe2371d6fa55521baef2bf6e22d9 to your computer and use it in GitHub Desktop.
Flutter: convert issue (2)
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:crypto/crypto.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
MyHomePage({Key key, this.title}) :
super(key: key);
@override
MyHomePageState createState() {
return new MyHomePageState();
}
}
class MyHomePageState extends State<MyHomePage> {
Stopwatch sw;
int ms;
int totalms;
int count;
@override
void initState(){
sw = Stopwatch();
count = 0;
totalms = 0;
convert();
super.initState();
}
void refresh(int i){
print("refresh with: $i");
setState(() {
count = i;
});
}
int convert(){
List<int> U_i = [121, -8, 43, -70, 22, -31, -22, -60, -32, 44, 74, -81, 22, -19, 25, 47, -40, 88, 22, -64, -64, -41, 45, 73, -46, 19, 13, 87, -53, 57, -75, -116, 0, 0, 0, 1];
int c = 50;
// int c = 10000;
List<int> password = [66, 97, 115, 115, 103, 64, 49, 57, 49, 57];
Hmac hmac = Hmac(sha256, password);
int l = 32;
// int l = 5;
for (int i = 1; i <= l; i++) {
sw.start();
for (int i = 0; i < c; i++) {
U_i = hmac.convert(U_i).bytes;
}
ms = sw.elapsedMilliseconds;
print('took ${ms} ms');
totalms+=ms;
refresh(i);
}
return U_i[0];
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(count.toString()),
Text(totalms.toString())
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment