/flash-src/third-party/com/hurlant/math/ClassicReduction.as

http://github.com/gimite/web-socket-js · ActionScript · 35 lines · 31 code · 1 blank · 3 comment · 2 complexity · 5c569ab3d2c2349d45214fd8ac38b32e MD5 · raw file

  1. package com.hurlant.math
  2. {
  3. use namespace bi_internal;
  4. /**
  5. * Modular reduction using "classic" algorithm
  6. */
  7. internal class ClassicReduction implements IReduction
  8. {
  9. private var m:BigInteger;
  10. public function ClassicReduction(m:BigInteger) {
  11. this.m = m;
  12. }
  13. public function convert(x:BigInteger):BigInteger {
  14. if (x.s<0 || x.compareTo(m)>=0) {
  15. return x.mod(m);
  16. }
  17. return x;
  18. }
  19. public function revert(x:BigInteger):BigInteger {
  20. return x;
  21. }
  22. public function reduce(x:BigInteger):void {
  23. x.divRemTo(m, null,x);
  24. }
  25. public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void {
  26. x.multiplyTo(y,r);
  27. reduce(r);
  28. }
  29. public function sqrTo(x:BigInteger, r:BigInteger):void {
  30. x.squareTo(r);
  31. reduce(r);
  32. }
  33. }
  34. }