Esempio n. 1
0
        public override int TransformFinal(ReadOnlySpan <byte> input, Span <byte> output)
        {
            int outputSize = 0;
            int blockSize  = BlockSizeInBytes;

            if (input.Length >= blockSize)
            {
                int alignedLength = input.Length - (input.Length % blockSize);
                outputSize += Transform(input.Slice(0, alignedLength), output.Slice(0, alignedLength));
                input       = input.Slice(alignedLength);
                output      = output.Slice(alignedLength);
            }

            if (input.Length > 0)
            {
                blockTransform.Transform(FR, FRE);
                // TODO: Vectorize
                for (int i = 0; i < input.Length; i++)
                {
                    FRE[i] ^= input[i];
                }
                FRE.AsSpan(0, output.Length).CopyTo(output);
                outputSize += output.Length;
            }

            // Reset vectors
            IV.CopyTo(FR.AsSpan());
            CryptographicOperations.ZeroMemory(FRE);

            return(outputSize);
        }
Esempio n. 2
0
        protected override void Execute(CodeActivityContext context)
        {
            var key        = Key.Get(context);
            var iv         = IV.Get(context);
            var cipherText = CipherText.Get(context);

            if (cipherText == null || cipherText.Length <= 0)
            {
                throw new ArgumentNullException("cipherText");
            }
            if (key == null || key.Length <= 0)
            {
                throw new ArgumentNullException("key");
            }

            string plaintext = null;

            using (AesManaged aes = new AesManaged())
            {
                ICryptoTransform decryptor = aes.CreateDecryptor(Encoding.UTF8.GetBytes(key), Encoding.UTF8.GetBytes(iv));
                using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(cipherText)))
                {
                    using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
                    {
                        using (StreamReader reader = new StreamReader(cs))
                            plaintext = reader.ReadToEnd();
                    }
                }
            }
            PlainText.Set(context, plaintext);
        }
Esempio n. 3
0
        protected override void Execute(CodeActivityContext context)
        {
            var key       = Key.Get(context);
            var iv        = IV.Get(context);
            var plainText = PlainText.Get(context);

            if (plainText == null || plainText.Length <= 0)
            {
                throw new ArgumentNullException("plainText");
            }
            if (key == null || key.Length <= 0)
            {
                throw new ArgumentNullException("key");
            }

            byte[] encrypted;
            using (AesManaged aes = new AesManaged())
            {
                ICryptoTransform encryptor = aes.CreateEncryptor(Encoding.UTF8.GetBytes(key), Encoding.UTF8.GetBytes(iv));
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter sw = new StreamWriter(cs))
                            sw.Write(plainText);
                        encrypted = ms.ToArray();
                    }
                }
            }

            var result = Convert.ToBase64String(encrypted);

            CipherText.Set(context, result);
        }
Esempio n. 4
0
        public TunnelDataMessage(I2PTunnelId desttunnel)
        {
            AllocateBuffer(DataLength + 4);

            TunnelId = desttunnel;
            IV.Randomize();
        }
Esempio n. 5
0
 public byte[] dameResume()
 {
     byte[] buffer = new byte[Key.Length + IV.Length];
     Key.CopyTo(buffer, 0);
     IV.CopyTo(buffer, Key.Length);
     return(buffer);
 }
Esempio n. 6
0
        /// <summary>
        /// Generate a Discord embed Pokemon message
        /// </summary>
        /// <param name="guildId">Guild the notification is for</param>
        /// <param name="client">Discord client</param>
        /// <param name="whConfig">Webhook config</param>
        /// <param name="alarm">Webhook alarm</param>
        /// <param name="city">City the Pokemon was found in</param>
        /// <returns>DiscordEmbedNotification object to send</returns>
        public async Task <DiscordEmbedNotification> GeneratePokemonMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            // If IV has value then use alarmText if not null otherwise use default. If no stats use default missing stats alarmText
            var server          = whConfig.Servers[guildId];
            var alertType       = IsMissingStats ? AlertMessageType.PokemonMissingStats : AlertMessageType.Pokemon;
            var alert           = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var pokemonImageUrl = IconFetcher.Instance.GetPokemonIcon(server.IconStyle, Id, FormId, 0, Gender, Costume, false);
            var properties      = await GetProperties(client.Guilds[guildId], whConfig, city, pokemonImageUrl);

            var eb = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = IV.BuildColor(),
                Footer       = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(await Task.FromResult(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            })));
        }
Esempio n. 7
0
        public void check_mud_shot_damage_vs_giratina()
        {
            Move ms = new Move("Mud Shot", PokeType.ground)
            {
            };

            ms.Power      = 3;
            ms.Energy     = 0;
            ms.EnergyGain = 9;
            ms.Cooldown   = 1000;

            var op_giratina_a = new IV(187, 225, 284)
            {
            };

            op_giratina_a.Attack  = 14;
            op_giratina_a.Defense = 7;
            op_giratina_a.HP      = 11;
            op_giratina_a.Level   = 26.5f;
            var op_cp = op_giratina_a.CP;

            Assert.IsTrue(op_cp == 2486);

            var stab  = 1;
            var r_atk = me_swampert.RealAttack;
            var r_def = op_giratina_a.RealDefense;

            float op_effect         = (float)r_atk / r_def;
            var   type_effect_bonus = 1.2;
            var   ms_damage         = ((int)Math.Floor(ms.Power * stab * op_effect * type_effect_bonus * 0.5 * bonus_multiplier) + 1);

            Assert.IsTrue(ms_damage == 3);
        }
Esempio n. 8
0
        private ICryptoTransform GetDecryptor(SymmetricAlgorithm algorithm)
        {
            byte[] ivBytes  = IV.ToByteArray();
            byte[] keyBytes = GetPasswordBytes();

            return(algorithm.CreateDecryptor(keyBytes, ivBytes));
        }
Esempio n. 9
0
 public byte[] EncryptAll(string raw)
 {
     byte[] IV;
     byte[] encrypted = AESEncrypt(out IV, Encoding.ASCII.GetBytes(raw));
     byte[] result    = new byte[IV.Length + encrypted.Length];
     IV.CopyTo(result, 0);
     encrypted.CopyTo(result, IVLength);
     return(result);
 }
Esempio n. 10
0
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                Duration.ToBytes(),
                MimeType.ToBytes(),
                Size.ToBytes(),
                Key.ToBytes(),
                IV.ToBytes()));
 }
 private ImmutableList <Tuple <FhirDateTime, FhirDecimal> > Convert_V(
     IV value)
 {
     return(value.Value
            .Select(
                i => new Tuple <FhirDateTime, FhirDecimal>(
                    i.t_IndexElement,
                    i.Value))
            .ToImmutableList());
 }
Esempio n. 12
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = (int)2166136261;
         hash = (hash * 16777619) ^ Key.GetHashCode();
         hash = (hash * 16777619) ^ IV.GetHashCode();
         return(hash);
     }
 }
Esempio n. 13
0
    void Start()
    {
        obj  = GameObject.FindGameObjectWithTag("Elevator");
        obj2 = GameObject.FindGameObjectWithTag("GameModeManager");

        OST_Intro = FMODUnity.RuntimeManager.CreateInstance("event:/OST/OST_Intro");
        OST_Intro.getParameter("MainGame", out MainGame);
        OST_Intro.getParameter("IV", out IV);
        MainGame.setValue(0);
        IV.setValue(0.9f);

        OST_Intro.start();

        OST_2 = FMODUnity.RuntimeManager.CreateInstance("event:/OST/OST_2");
        OST_2.getParameter("MainGame2", out MainGame2);
        OST_2.getParameter("OV", out OV);
        OST_2.getParameter("EndGame", out EndGame);
        OST_2.getParameter("GameOver", out GameOver);
        MainGame2.setValue(0);
        EndGame.setValue(0);
        GameOver.setValue(0);
        OV.setValue(0.9f);

        FluxEffect = FMODUnity.RuntimeManager.CreateInstance("event:/SD/FluxCarrier");
        FluxEffect.getParameter("FV", out FV);
        FV.setValue(0.8f);

        Checkpoint = FMODUnity.RuntimeManager.CreateInstance("event:/SD/Hexagon");
        Checkpoint.getParameter("HV", out HV);
        Checkpoint.getParameter("HP", out HP);
        HV.setValue(0.95f);
        HP.setValue(0);

        Jump = FMODUnity.RuntimeManager.CreateInstance("event:/SD/Jump");
        Jump.getParameter("JV", out JV);
        JV.setValue(0.8f);

        Headroll = FMODUnity.RuntimeManager.CreateInstance("event:/SD/Headroll");
        Headroll.getParameter("HRV", out HRV);
        HRV.setValue(0.75f);

        JumpPad = FMODUnity.RuntimeManager.CreateInstance("event:/SD/JumpPad");
        JumpPad.getParameter("JPV", out JPV);
        JPV.setValue(0.74f);

        Atmosphere = FMODUnity.RuntimeManager.CreateInstance("event:/SD/Atmosphere");
        Atmosphere.getParameter("AV", out AV);
        AV.setValue(0.7f);

        Atmosphere.start();

        Stinger = FMODUnity.RuntimeManager.CreateInstance("event:/SD/Stinger");
        Stinger.getParameter("STV", out STV);
        STV.setValue(0.8f);
    }
Esempio n. 14
0
 public void Setup()
 {
     me_swampert = new IV(208, 175, 225)
     {
     };
     me_swampert.Attack  = 6;
     me_swampert.Defense = 15;
     me_swampert.HP      = 9;
     me_swampert.Level   = 32f;
     me_cp = me_swampert.CP;
 }
Esempio n. 15
0
        /// <inheritdoc />
        protected override void InitState(byte[] key)
        {
            // Prepend the supplied IV with zeros (as per FIPS PUB 81)
            byte[] workingIv = new byte[CipherBlockSize];
            IV.DeepCopy_NoChecks(0, workingIv, CipherBlockSize - IV.Length, IV.Length);
            Array.Clear(workingIv, 0, CipherBlockSize - IV.Length);
            IV = workingIv;

            Reset();
            BlockCipher.Init(true, key); // Streaming mode - cipher always used in encryption mode
        }
Esempio n. 16
0
        public void save(string salida)
        {
            FileStream fStream = new FileStream(salida, FileMode.OpenOrCreate);

            byte[] buffer = new byte[Key.Length + IV.Length];
            Key.CopyTo(buffer, 0);
            IV.CopyTo(buffer, Key.Length);
            byte[] encryptedData = ProtectedData.Protect(buffer, entropy, DataProtectionScope.CurrentUser);
            fStream.Write(encryptedData, 0, encryptedData.Length);
            fStream.Close();
        }
Esempio n. 17
0
        public override void ToStream(Stream output)
        {
            output.Write(TLUtils.SignatureToBytes(Signature));
            output.Write(Duration.ToBytes());
            output.Write(MimeType.ToBytes());
            output.Write(Size.ToBytes());
            output.Write(Key.ToBytes());
            output.Write(IV.ToBytes());

            UserId.NullableToStream(output);
            File.NullableToStream(output);
        }
Esempio n. 18
0
        public void Lickilicky_CP_2467_at_Level_40_for_perfect_iv()
        {
            IV iv = new IV(161, 181, 242)
            {
            };

            iv.Attack  = 15;
            iv.Defense = 15;
            iv.HP      = 15;
            iv.Level   = 40;
            Assert.IsTrue(iv.CP == 2467);
        }
Esempio n. 19
0
        public void Giratina_Alt_CP_2486_at_Level_26_5_for_14_7_11_iv()
        {
            IV iv = new IV(187, 225, 284)
            {
            };

            iv.Attack  = 14;
            iv.Defense = 7;
            iv.HP      = 11;
            iv.Level   = 26.5f;
            Assert.IsTrue(iv.CP == 2486);
        }
Esempio n. 20
0
        public void Azu_CP_1486_at_Level_40_5_for_rank_77()
        {
            IV iv = new IV(112, 152, 225)
            {
            };

            iv.Attack  = 7;
            iv.Defense = 14;
            iv.HP      = 13;
            iv.Level   = 40.5f;
            Assert.IsTrue(iv.CP == 1486);
        }
Esempio n. 21
0
        public void Shiftry_CP_2333_at_Level_40_for_perfect_iv()
        {
            IV iv = new IV(200, 121, 207)
            {
            };

            iv.Attack  = 15;
            iv.Defense = 15;
            iv.HP      = 15;
            iv.Level   = 40;
            Assert.IsTrue(iv.CP == 2333);
        }
Esempio n. 22
0
        public void Setup()
        {
            me = new IV(143, 285, 190)
            {
            };
            me.Attack  = 15;
            me.Defense = 13;
            me.HP      = 15;
            me.Level   = 41;
            var cp = me.CP;

            Assert.IsTrue(cp == 2470);
        }
Esempio n. 23
0
        public void Setup()
        {
            me_giratina_a = new IV(187, 225, 284)
            {
            };
            me_giratina_a.Attack  = 14;
            me_giratina_a.Defense = 7;
            me_giratina_a.HP      = 11;
            me_giratina_a.Level   = 26.5f;
            var cp = me_giratina_a.CP;

            Assert.IsTrue(cp == 2486);
        }
Esempio n. 24
0
 public override void ToStream(Stream output)
 {
     output.Write(TLUtils.SignatureToBytes(Signature));
     output.Write(Thumb.ToBytes());
     output.Write(ThumbW.ToBytes());
     output.Write(ThumbH.ToBytes());
     output.Write(FileName.ToBytes());
     output.Write(MimeType.ToBytes());
     output.Write(Size.ToBytes());
     output.Write(Key.ToBytes());
     output.Write(IV.ToBytes());
     File.NullableToStream(output);
 }
Esempio n. 25
0
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                Thumb.ToBytes(),
                ThumbW.ToBytes(),
                ThumbH.ToBytes(),
                FileName.ToBytes(),
                MimeType.ToBytes(),
                Size.ToBytes(),
                Key.ToBytes(),
                IV.ToBytes()));
 }
Esempio n. 26
0
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                Thumb.ToBytes(),
                ThumbW.ToBytes(),
                ThumbH.ToBytes(),
                Duration.ToBytes(),
                W.ToBytes(),
                H.ToBytes(),
                Size.ToBytes(),
                Key.ToBytes(),
                IV.ToBytes()));
 }
Esempio n. 27
0
        private void OpenKey(IntPtr algorithm, byte[] key, int effectiveKeyLength)
        {
            _ctx = Interop.Crypto.EvpCipherCreate(
                algorithm,
                ref MemoryMarshal.GetReference(key.AsSpan()),
                key.Length * 8,
                effectiveKeyLength,
                ref MemoryMarshal.GetReference(IV.AsSpan()),
                _encrypting ? 1 : 0);

            Interop.Crypto.CheckValidOpenSslHandle(_ctx);

            // OpenSSL will happily do PKCS#7 padding for us, but since we support padding modes
            // that it doesn't (PaddingMode.Zeros) we'll just always pad the blocks ourselves.
            CheckBoolReturn(Interop.Crypto.EvpCipherCtxSetPadding(_ctx, 0));
        }
Esempio n. 28
0
        public static byte[] SerializateMessage(string message, TlsManager tlsManager, RsaManager rsaManager)
        {
            byte[] IV,
            hashSum,
            digitalSignature,
            hashSumCount,
            messageBytes;
            string publicRSAKey = rsaManager.PublicKey;

            message = $"|rsaKeyStart|{publicRSAKey}|rsaKeyEnd|{message}";

            messageBytes     = tlsManager.EncryptMessage(message, out IV, out hashSum);
            hashSumCount     = new byte[] { (byte)hashSum.Length };
            digitalSignature = rsaManager.GetDigitalSignature(hashSum);

            return(IV.Concat(hashSumCount.Concat(hashSum.Concat(digitalSignature.Concat(messageBytes)))).ToArray());
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (IV.Length != 0)
            {
                hash ^= IV.GetHashCode();
            }
            if (Key.Length != 0)
            {
                hash ^= Key.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 30
0
        private IEncryptor GetEncryptor(ICipher cipher)
        {
            if (cipher == null)
            {
                return(null);
            }

            switch (modesComboBox.Text)
            {
            case nameof(ECB):
                return(new ECB(cipher, _padding));

            case nameof(CBC):
                return(new CBC(cipher, _padding, IV.GetRandom(cipher.BlockSize)));

            default:
                return(null);
            }
        }