Simple hex excercises

controllers.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. function MainController($scope, $routeParams) {
  3. $scope.allowedLengths = [4, 8, 16, 32, 64, 128, 256];
  4. $scope.binaryLength = 64;
  5. $scope.binary = generateBinary($scope.binaryLength);
  6. $scope.parts = [];
  7. $scope.hex = "";
  8. $scope.displayResults = function () {
  9. return $scope.hex.length > 0;
  10. };
  11. $scope.generate = function () {
  12. $scope.binary = generateBinary($scope.binaryLength);
  13. $scope.parts = [];
  14. $scope.hex = "";
  15. return false;
  16. };
  17. $scope.solve = function () {
  18. $scope.parts = [];
  19. $scope.hex = "";
  20. var original = $scope.binary;
  21. while (original.length > 0) {
  22. // Find the 16 bytes we need.
  23. var part = original.substr(-4);
  24. var character = binaryToHex(part);
  25. // Divvy this stuff up.
  26. $scope.parts.push({ "binary": part, "hex": character });
  27. $scope.hex = character + $scope.hex;
  28. // Remove the last four.
  29. original = original.substr(0, original.length - 4);
  30. }
  31. return false;
  32. };
  33. }